add httparty option config
This commit is contained in:
@@ -31,7 +31,7 @@ module Downloads
|
|||||||
}
|
}
|
||||||
@source, headers, @data = before_download(@source, headers, @data)
|
@source, headers, @data = before_download(@source, headers, @data)
|
||||||
url = URI.parse(@source)
|
url = URI.parse(@source)
|
||||||
res = HTTParty.head(url, timeout: 3)
|
res = HTTParty.head(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
||||||
res.content_length
|
res.content_length
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ module Downloads
|
|||||||
validate_local_hosts(url)
|
validate_local_hosts(url)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
res = HTTParty.get(url, timeout: 10, headers: headers)
|
res = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 10, headers: headers))
|
||||||
if res.success?
|
if res.success?
|
||||||
if max_size
|
if max_size
|
||||||
len = res["Content-Length"]
|
len = res["Content-Length"]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module Downloads
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def http_head_request(url, headers)
|
def http_head_request(url, headers)
|
||||||
HTTParty.head(url, headers: headers)
|
HTTParty.head(url, Danbooru.config.httparty_options.merge(headers: headers))
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_exists?(url, headers)
|
def http_exists?(url, headers)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class ImageProxy
|
|||||||
"Referer" => fake_referer_for(url),
|
"Referer" => fake_referer_for(url),
|
||||||
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
|
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
|
||||||
}
|
}
|
||||||
response = HTTParty.get(url, headers: headers)
|
response = HTTParty.get(url, Danbooru.config.httparty_options.merge(headers: headers))
|
||||||
if response.success?
|
if response.success?
|
||||||
return response
|
return response
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ module Iqdb
|
|||||||
uri = URI.parse("#{Danbooru.config.iqdbs_server}/similar")
|
uri = URI.parse("#{Danbooru.config.iqdbs_server}/similar")
|
||||||
uri.query = URI.encode_www_form(params)
|
uri.query = URI.encode_www_form(params)
|
||||||
|
|
||||||
resp = HTTParty.get(uri)
|
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
json = JSON.parse(resp.body)
|
json = JSON.parse(resp.body)
|
||||||
if json.is_a?(Array)
|
if json.is_a?(Array)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class MissedSearchService
|
|||||||
def fetch_data
|
def fetch_data
|
||||||
Cache.get("ms", 1.minute) do
|
Cache.get("ms", 1.minute) do
|
||||||
url = URI.parse("#{Danbooru.config.reportbooru_server}/missed_searches")
|
url = URI.parse("#{Danbooru.config.reportbooru_server}/missed_searches")
|
||||||
response = HTTParty.get(url, timeout: 6)
|
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 6))
|
||||||
if response.success?
|
if response.success?
|
||||||
response = response.body
|
response = response.body
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class NicoSeigaApiClient
|
|||||||
|
|
||||||
def get_illust(id)
|
def get_illust(id)
|
||||||
uri = "#{BASE_URL}/illust/info?id=#{id}"
|
uri = "#{BASE_URL}/illust/info?id=#{id}"
|
||||||
resp = HTTParty.get(uri)
|
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
parse_illust_xml_response(resp.body)
|
parse_illust_xml_response(resp.body)
|
||||||
end
|
end
|
||||||
@@ -17,7 +17,7 @@ class NicoSeigaApiClient
|
|||||||
|
|
||||||
def get_artist(id)
|
def get_artist(id)
|
||||||
uri = "#{BASE_URL}/user/info?id=#{id}"
|
uri = "#{BASE_URL}/user/info?id=#{id}"
|
||||||
resp = HTTParty.get(uri)
|
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
parse_artist_xml_response(resp.body)
|
parse_artist_xml_response(resp.body)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class PixivApiClient
|
|||||||
url.query = URI.encode_www_form(params)
|
url.query = URI.encode_www_form(params)
|
||||||
json = nil
|
json = nil
|
||||||
|
|
||||||
resp = HTTParty.get(url)
|
resp = HTTParty.get(url, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
json = parse_api_json(resp.body)
|
json = parse_api_json(resp.body)
|
||||||
else
|
else
|
||||||
@@ -173,7 +173,7 @@ private
|
|||||||
}
|
}
|
||||||
url = "https://oauth.secure.pixiv.net/auth/token"
|
url = "https://oauth.secure.pixiv.net/auth/token"
|
||||||
|
|
||||||
resp = HTTParty.post(url, body: params, headers: headers)
|
resp = HTTParty.post(url, Danbooru.config.httparty_options.merge(body: params, headers: headers))
|
||||||
if resp.success?
|
if resp.success?
|
||||||
json = JSON.parse(resp.body)
|
json = JSON.parse(resp.body)
|
||||||
access_token = json["response"]["access_token"]
|
access_token = json["response"]["access_token"]
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class PopularSearchService
|
|||||||
|
|
||||||
Cache.get("ps-#{scale}-#{dates}", 1.minute) do
|
Cache.get("ps-#{scale}-#{dates}", 1.minute) do
|
||||||
url = "#{Danbooru.config.reportbooru_server}/hits/#{scale}?date=#{dates}"
|
url = "#{Danbooru.config.reportbooru_server}/hits/#{scale}?date=#{dates}"
|
||||||
response = HTTParty.get(url, timeout: 3)
|
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
||||||
if response.success?
|
if response.success?
|
||||||
response = response.body
|
response = response.body
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module Reports
|
|||||||
uri = URI.parse("#{Danbooru.config.reportbooru_server}/reports/#{endpoint}")
|
uri = URI.parse("#{Danbooru.config.reportbooru_server}/reports/#{endpoint}")
|
||||||
uri.query = URI.encode_www_form(params)
|
uri.query = URI.encode_www_form(params)
|
||||||
|
|
||||||
resp = HTTParty.get(uri)
|
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
resp.body
|
resp.body
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ module Sources::Strategies
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
resp = HTTParty.get(api_url)
|
resp = HTTParty.get(api_url, Danbooru.config.httparty_options)
|
||||||
image_url_rewriter = Downloads::RewriteStrategies::ArtStation.new
|
image_url_rewriter = Downloads::RewriteStrategies::ArtStation.new
|
||||||
if resp.success?
|
if resp.success?
|
||||||
@json = JSON.parse(resp.body)
|
@json = JSON.parse(resp.body)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TagAliasCorrection
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fill_hash!
|
def fill_hash!
|
||||||
res = HTTParty.get("http://#{hostname}/tag_aliases/#{tag_alias_id}/correction.json")
|
res = HTTParty.get("http://#{hostname}/tag_aliases/#{tag_alias_id}/correction.json", Danbooru.config.httparty_options)
|
||||||
if res.success?
|
if res.success?
|
||||||
json = JSON.parse(res.body)
|
json = JSON.parse(res.body)
|
||||||
statistics_hash["antecedent_cache"] = json["antecedent_cache"]
|
statistics_hash["antecedent_cache"] = json["antecedent_cache"]
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TagCorrection
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fill_hash!
|
def fill_hash!
|
||||||
res = HTTParty.get("http://#{hostname}/tags/#{tag_id}/correction.json")
|
res = HTTParty.get("http://#{hostname}/tags/#{tag_id}/correction.json", Danbooru.config.httparty_options)
|
||||||
if res.success?
|
if res.success?
|
||||||
json = JSON.parse(res.body)
|
json = JSON.parse(res.body)
|
||||||
statistics_hash["category_cache"] = json["category_cache"]
|
statistics_hash["category_cache"] = json["category_cache"]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class TumblrApiClient < Struct.new(:api_key)
|
|||||||
base_uri "https://api.tumblr.com/v2/blog/"
|
base_uri "https://api.tumblr.com/v2/blog/"
|
||||||
|
|
||||||
def posts(blog_name, post_id)
|
def posts(blog_name, post_id)
|
||||||
response = self.class.get("/#{blog_name}/posts", query: { id: post_id, api_key: api_key })
|
response = self.class.get("/#{blog_name}/posts", Danbooru.config.httparty_options.merge(query: { id: post_id, api_key: api_key }))
|
||||||
response.parsed_response.with_indifferent_access[:response]
|
response.parsed_response.with_indifferent_access[:response]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class TwitterService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def extract_og_image_from_page(url)
|
def extract_og_image_from_page(url)
|
||||||
resp = HTTParty.get(url)
|
resp = HTTParty.get(url, Danbooru.config.httparty_options)
|
||||||
if resp.success?
|
if resp.success?
|
||||||
doc = Nokogiri::HTML(resp.body)
|
doc = Nokogiri::HTML(resp.body)
|
||||||
images = doc.css("meta[property='og:image']")
|
images = doc.css("meta[property='og:image']")
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SavedSearch < ApplicationRecord
|
|||||||
|
|
||||||
uri = "#{Danbooru.config.listbooru_server}/v2/search"
|
uri = "#{Danbooru.config.listbooru_server}/v2/search"
|
||||||
|
|
||||||
resp = HTTParty.post(uri, body: json)
|
resp = HTTParty.post(uri, Danbooru.config.httparty_options.merge(body: json))
|
||||||
if resp.success?
|
if resp.success?
|
||||||
resp.body.to_s.scan(/\d+/).map(&:to_i)
|
resp.body.to_s.scan(/\d+/).map(&:to_i)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class User < ApplicationRecord
|
|||||||
def update_remote_cache
|
def update_remote_cache
|
||||||
if name_changed?
|
if name_changed?
|
||||||
Danbooru.config.other_server_hosts.each do |server|
|
Danbooru.config.other_server_hosts.each do |server|
|
||||||
HTTParty.delete("http://#{server}/users/#{id}/cache")
|
HTTParty.delete("http://#{server}/users/#{id}/cache", Danbooru.config.httparty_options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception
|
rescue Exception
|
||||||
|
|||||||
@@ -417,10 +417,10 @@ module Danbooru
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
# for outgoing http requests, use these proxy settings:
|
def httparty_options
|
||||||
def http_proxy_settings
|
# proxy example:
|
||||||
# {http_proxyaddr: "", http_proxyport: "", http_proxyuser: nil, http_proxypass: nil}
|
# {http_proxyaddr: "", http_proxyport: "", http_proxyuser: nil, http_proxypass: nil}
|
||||||
nil
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
# you should override this
|
# you should override this
|
||||||
|
|||||||
Reference in New Issue
Block a user