Upgrade http.rb gem to 5.0.4.
Fixes a bug where the Foundation source strategy failed because http.rb automatically sent a `Content-Length: 0` header with all GET requests, which caused Foundation to return a 400 Bad Request error. This behavior was fixed in http.rb 5.x. http.rb 5.x has a breaking change where it now includes the request object inside the response object, which we have to handle in a few places.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -30,7 +30,7 @@ gem 'builder'
|
|||||||
gem 'puma'
|
gem 'puma'
|
||||||
gem 'scenic'
|
gem 'scenic'
|
||||||
gem 'ipaddress_2'
|
gem 'ipaddress_2'
|
||||||
gem 'http', "~> 4.4.1"
|
gem 'http'
|
||||||
gem 'activerecord-hierarchical_query', git: "https://github.com/danbooru/activerecord-hierarchical_query"
|
gem 'activerecord-hierarchical_query', git: "https://github.com/danbooru/activerecord-hierarchical_query"
|
||||||
gem 'http-cookie', git: "https://github.com/danbooru/http-cookie"
|
gem 'http-cookie', git: "https://github.com/danbooru/http-cookie"
|
||||||
gem 'pundit'
|
gem 'pundit'
|
||||||
|
|||||||
13
Gemfile.lock
13
Gemfile.lock
@@ -266,14 +266,12 @@ GEM
|
|||||||
heapy (0.2.0)
|
heapy (0.2.0)
|
||||||
thor
|
thor
|
||||||
hsluv (1.0.1)
|
hsluv (1.0.1)
|
||||||
http (4.4.1)
|
http (5.0.4)
|
||||||
addressable (~> 2.3)
|
addressable (~> 2.8)
|
||||||
http-cookie (~> 1.0)
|
http-cookie (~> 1.0)
|
||||||
http-form_data (~> 2.2)
|
http-form_data (~> 2.2)
|
||||||
http-parser (~> 1.2.0)
|
llhttp-ffi (~> 0.4.0)
|
||||||
http-form_data (2.3.0)
|
http-form_data (2.3.0)
|
||||||
http-parser (1.2.3)
|
|
||||||
ffi-compiler (>= 1.0, < 2.0)
|
|
||||||
httpclient (2.8.3)
|
httpclient (2.8.3)
|
||||||
i18n (1.9.1)
|
i18n (1.9.1)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
@@ -290,6 +288,9 @@ GEM
|
|||||||
listen (3.7.1)
|
listen (3.7.1)
|
||||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||||
rb-inotify (~> 0.9, >= 0.9.10)
|
rb-inotify (~> 0.9, >= 0.9.10)
|
||||||
|
llhttp-ffi (0.4.0)
|
||||||
|
ffi-compiler (~> 1.0)
|
||||||
|
rake (~> 13.0)
|
||||||
loofah (2.14.0)
|
loofah (2.14.0)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
@@ -568,7 +569,7 @@ DEPENDENCIES
|
|||||||
google-cloud-bigquery
|
google-cloud-bigquery
|
||||||
google-cloud-storage
|
google-cloud-storage
|
||||||
hsluv
|
hsluv
|
||||||
http (~> 4.4.1)
|
http
|
||||||
http-cookie!
|
http-cookie!
|
||||||
ipaddress_2
|
ipaddress_2
|
||||||
listen
|
listen
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ module Danbooru
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fake_response(status)
|
def fake_response(status)
|
||||||
::HTTP::Response.new(status: status, version: "1.1", body: "")
|
::HTTP::Response.new(status: status, version: "1.1", body: "", request: nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ module Danbooru
|
|||||||
response.flush
|
response.flush
|
||||||
response.body.instance_variable_set(:@connection, nil)
|
response.body.instance_variable_set(:@connection, nil)
|
||||||
response.body.instance_variable_set(:@stream, nil)
|
response.body.instance_variable_set(:@stream, nil)
|
||||||
|
response.instance_exec { @request = request.dup }
|
||||||
|
response.request.instance_exec { @uri_normalizer = nil }
|
||||||
|
response.request.body.instance_exec { @source = nil }
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module IqdbTestHelper
|
module IqdbTestHelper
|
||||||
def mock_iqdb_matches(matches)
|
def mock_iqdb_matches(matches)
|
||||||
Danbooru.config.stubs(:iqdb_url).returns("http://localhost:5588")
|
Danbooru.config.stubs(:iqdb_url).returns("http://localhost:5588")
|
||||||
response = HTTP::Response.new(status: 200, body: matches.to_json, headers: { "Content-Type": "application/json" }, version: "1.1")
|
response = HTTP::Response.new(status: 200, body: matches.to_json, headers: { "Content-Type": "application/json" }, version: "1.1", request: nil)
|
||||||
HTTP::Client.any_instance.stubs(:post).returns(response)
|
HTTP::Client.any_instance.stubs(:post).returns(response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module ReportbooruHelper
|
module ReportbooruHelper
|
||||||
def mock_request(url, method: :get, status: 200, body: nil, http: Danbooru::Http.any_instance, **options)
|
def mock_request(url, method: :get, status: 200, body: nil, http: Danbooru::Http.any_instance, **options)
|
||||||
response = HTTP::Response.new(status: status, body: body, version: "1.1")
|
response = HTTP::Response.new(status: status, body: body, version: "1.1", request: nil)
|
||||||
http.stubs(method).with(url, **options).returns(response)
|
http.stubs(method).with(url, **options).returns(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "retriable feature" do
|
context "retriable feature" do
|
||||||
should "retry immediately if no Retry-After header is sent" do
|
should "retry immediately if no Retry-After header is sent" do
|
||||||
response_429 = ::HTTP::Response.new(status: 429, version: "1.1", body: "")
|
response_429 = ::HTTP::Response.new(status: 429, version: "1.1", body: "", request: nil)
|
||||||
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "")
|
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "", request: nil)
|
||||||
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_429, response_200)
|
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_429, response_200)
|
||||||
|
|
||||||
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/429"))
|
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/429"))
|
||||||
@@ -132,8 +132,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "retry if the Retry-After header is an integer" do
|
should "retry if the Retry-After header is an integer" do
|
||||||
response_503 = ::HTTP::Response.new(status: 503, version: "1.1", headers: { "Retry-After": "1" }, body: "")
|
response_503 = ::HTTP::Response.new(status: 503, version: "1.1", headers: { "Retry-After": "1" }, body: "", request: nil)
|
||||||
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "")
|
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "", request: nil)
|
||||||
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
|
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
|
||||||
|
|
||||||
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/503"))
|
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/503"))
|
||||||
@@ -141,8 +141,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "retry if the Retry-After header is a date" do
|
should "retry if the Retry-After header is a date" do
|
||||||
response_503 = ::HTTP::Response.new(status: 503, version: "1.1", headers: { "Retry-After": 2.seconds.from_now.httpdate }, body: "")
|
response_503 = ::HTTP::Response.new(status: 503, version: "1.1", headers: { "Retry-After": 2.seconds.from_now.httpdate }, body: "", request: nil)
|
||||||
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "")
|
response_200 = ::HTTP::Response.new(status: 200, version: "1.1", body: "", request: nil)
|
||||||
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
|
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
|
||||||
|
|
||||||
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/503"))
|
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/503"))
|
||||||
@@ -166,7 +166,7 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
|||||||
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"
|
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)
|
response = Danbooru::Http.use(:unpolish_cloudflare).get(url)
|
||||||
|
|
||||||
assert_equal(200, response.status)
|
assert_equal(200, response.status.to_i)
|
||||||
assert_equal(622_784, response.content_length)
|
assert_equal(622_784, response.content_length)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ class ReportbooruServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "return nothing on failure" do
|
should "return nothing on failure" do
|
||||||
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1"))
|
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1", request: nil))
|
||||||
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date.yesterday}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1"))
|
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date.yesterday}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1", request: nil))
|
||||||
|
|
||||||
assert_equal([], @service.popular_posts(@date))
|
assert_equal([], @service.popular_posts(@date))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user