add httparty option config

This commit is contained in:
r888888888
2017-07-12 15:52:09 -07:00
parent 7f4d3052b3
commit 97ce9cafac
17 changed files with 22 additions and 22 deletions

View File

@@ -31,7 +31,7 @@ module Downloads
}
@source, headers, @data = before_download(@source, headers, @data)
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
end
@@ -90,7 +90,7 @@ module Downloads
validate_local_hosts(url)
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 max_size
len = res["Content-Length"]

View File

@@ -21,7 +21,7 @@ module Downloads
protected
def http_head_request(url, headers)
HTTParty.head(url, headers: headers)
HTTParty.head(url, Danbooru.config.httparty_options.merge(headers: headers))
end
def http_exists?(url, headers)

View File

@@ -20,7 +20,7 @@ class ImageProxy
"Referer" => fake_referer_for(url),
"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?
return response
else

View File

@@ -28,7 +28,7 @@ module Iqdb
uri = URI.parse("#{Danbooru.config.iqdbs_server}/similar")
uri.query = URI.encode_www_form(params)
resp = HTTParty.get(uri)
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
if resp.success?
json = JSON.parse(resp.body)
if json.is_a?(Array)

View File

@@ -17,7 +17,7 @@ class MissedSearchService
def fetch_data
Cache.get("ms", 1.minute) do
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?
response = response.body
else

View File

@@ -9,7 +9,7 @@ class NicoSeigaApiClient
def get_illust(id)
uri = "#{BASE_URL}/illust/info?id=#{id}"
resp = HTTParty.get(uri)
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
if resp.success?
parse_illust_xml_response(resp.body)
end
@@ -17,7 +17,7 @@ class NicoSeigaApiClient
def get_artist(id)
uri = "#{BASE_URL}/user/info?id=#{id}"
resp = HTTParty.get(uri)
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
if resp.success?
parse_artist_xml_response(resp.body)
end

View File

@@ -137,7 +137,7 @@ class PixivApiClient
url.query = URI.encode_www_form(params)
json = nil
resp = HTTParty.get(url)
resp = HTTParty.get(url, Danbooru.config.httparty_options)
if resp.success?
json = parse_api_json(resp.body)
else
@@ -173,7 +173,7 @@ private
}
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?
json = JSON.parse(resp.body)
access_token = json["response"]["access_token"]

View File

@@ -28,7 +28,7 @@ class PopularSearchService
Cache.get("ps-#{scale}-#{dates}", 1.minute) do
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?
response = response.body
else

View File

@@ -33,7 +33,7 @@ module Reports
uri = URI.parse("#{Danbooru.config.reportbooru_server}/reports/#{endpoint}")
uri.query = URI.encode_www_form(params)
resp = HTTParty.get(uri)
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
if resp.success?
resp.body
else

View File

@@ -46,7 +46,7 @@ module Sources::Strategies
end
def get
resp = HTTParty.get(api_url)
resp = HTTParty.get(api_url, Danbooru.config.httparty_options)
image_url_rewriter = Downloads::RewriteStrategies::ArtStation.new
if resp.success?
@json = JSON.parse(resp.body)

View File

@@ -22,7 +22,7 @@ class TagAliasCorrection
end
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?
json = JSON.parse(res.body)
statistics_hash["antecedent_cache"] = json["antecedent_cache"]

View File

@@ -19,7 +19,7 @@ class TagCorrection
end
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?
json = JSON.parse(res.body)
statistics_hash["category_cache"] = json["category_cache"]

View File

@@ -3,7 +3,7 @@ class TumblrApiClient < Struct.new(:api_key)
base_uri "https://api.tumblr.com/v2/blog/"
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]
end
end

View File

@@ -33,7 +33,7 @@ class TwitterService
end
def extract_og_image_from_page(url)
resp = HTTParty.get(url)
resp = HTTParty.get(url, Danbooru.config.httparty_options)
if resp.success?
doc = Nokogiri::HTML(resp.body)
images = doc.css("meta[property='og:image']")

View File

@@ -30,7 +30,7 @@ class SavedSearch < ApplicationRecord
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?
resp.body.to_s.scan(/\d+/).map(&:to_i)
else

View File

@@ -174,7 +174,7 @@ class User < ApplicationRecord
def update_remote_cache
if name_changed?
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
rescue Exception

View File

@@ -417,10 +417,10 @@ module Danbooru
false
end
# for outgoing http requests, use these proxy settings:
def http_proxy_settings
def httparty_options
# proxy example:
# {http_proxyaddr: "", http_proxyport: "", http_proxyuser: nil, http_proxypass: nil}
nil
{}
end
# you should override this