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:
20
app/logical/danbooru/http/unpolish_cloudflare.rb
Normal file
20
app/logical/danbooru/http/unpolish_cloudflare.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# Bypass Cloudflare Polish (https://support.cloudflare.com/hc/en-us/articles/360000607372-Using-Cloudflare-Polish-to-compress-images)
|
||||
|
||||
module Danbooru
|
||||
class Http
|
||||
class UnpolishCloudflare < HTTP::Feature
|
||||
HTTP::Options.register_feature :unpolish_cloudflare, self
|
||||
|
||||
def perform(request, &block)
|
||||
response = yield request
|
||||
|
||||
if response.headers["CF-Polished"].present?
|
||||
request.uri.query_values = request.uri.query_values.to_h.merge(danbooru_no_polish: SecureRandom.uuid)
|
||||
response = yield request
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user