danbooru::http: factor out Cloudflare Polish bypassing.
* Factor out the Cloudflare Polish bypass code to a standalone feature. * Add `http_downloader` method to the base source strategy. This is a HTTP client that should be used for downloading images or making requests to images. This client ensures that referrer spoofing and Cloudflare bypassing are performed. This fixes a bug with the upload page reporting the polished filesize instead of the original filesize when uploading ArtStation images.
This commit is contained in:
@@ -129,13 +129,23 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
||||
|
||||
context "spoof referrer feature" do
|
||||
should "spoof the referer" do
|
||||
response = Danbooru::Http.get("https://httpbin.org/anything")
|
||||
response = Danbooru::Http.use(:spoof_referrer).get("https://httpbin.org/anything")
|
||||
|
||||
assert_equal(200, response.status)
|
||||
assert_equal("https://httpbin.org", response.parse.dig("headers", "Referer"))
|
||||
end
|
||||
end
|
||||
|
||||
context "unpolish cloudflare feature" do
|
||||
should "return the original image for polished images" do
|
||||
url = "https://cdnb.artstation.com/p/assets/images/images/025/273/307/4k/atey-ghailan-a-sage-keyart-s-ch-04-outlined-1.jpg?1585246642"
|
||||
response = Danbooru::Http.use(:unpolish_cloudflare).get(url)
|
||||
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(720_743, response.content_length)
|
||||
end
|
||||
end
|
||||
|
||||
context "#download method" do
|
||||
should "download files" do
|
||||
response, file = Danbooru::Http.download_media("https://httpbin.org/bytes/1000")
|
||||
|
||||
Reference in New Issue
Block a user