Set the default User-Agent sent for outgoing http requests.

* Add a `Danbooru.config.http_headers` config option.

* Refactor various places to use this option instead of setting the user
  agent manually.
This commit is contained in:
evazion
2017-07-19 19:37:14 -05:00
parent d48ed95191
commit 8125d8e796
8 changed files with 29 additions and 48 deletions

View File

@@ -5,7 +5,7 @@ module Downloads
# example: https://cdnb3.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974
if url =~ %r!^https?://cdn\w*\.artstation\.com/p/assets/images/images/\d+/\d+/\d+/(?:medium|small|large)/!
original_url, headers = rewrite_large_url(url, headers)
if test_original(original_url)
if http_exists?(original_url, headers)
url = original_url
end
else
@@ -16,11 +16,6 @@ module Downloads
end
protected
def test_original(url)
res = http_head_request(url, {})
res.success?
end
def rewrite_html_url(url, headers)
return [url, headers] unless Sources::Strategies::ArtStation.url_match?(url)

View File

@@ -20,12 +20,8 @@ module Downloads
end
protected
def http_head_request(url, headers)
HTTParty.head(url, Danbooru.config.httparty_options.merge(headers: headers))
end
def http_exists?(url, headers)
res = http_head_request(url, headers)
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
res.success?
end
end