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:
evazion
2022-02-21 17:47:06 -06:00
parent 35dca33abc
commit fbab273c81
8 changed files with 23 additions and 19 deletions

View File

@@ -123,8 +123,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
context "retriable feature" do
should "retry immediately if no Retry-After header is sent" do
response_429 = ::HTTP::Response.new(status: 429, version: "1.1", body: "")
response_200 = ::HTTP::Response.new(status: 200, 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: "", request: nil)
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_429, response_200)
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/429"))
@@ -132,8 +132,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
end
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_200 = ::HTTP::Response.new(status: 200, version: "1.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: "", request: nil)
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
response = Danbooru::Http.use(:retriable).get(httpbin_url("status/503"))
@@ -141,8 +141,8 @@ class DanbooruHttpTest < ActiveSupport::TestCase
end
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_200 = ::HTTP::Response.new(status: 200, version: "1.1", 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: "", request: nil)
HTTP::Client.any_instance.expects(:perform).times(2).returns(response_503, response_200)
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"
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)
end
end

View File

@@ -16,8 +16,8 @@ class ReportbooruServiceTest < ActiveSupport::TestCase
end
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.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}").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", request: nil))
assert_equal([], @service.popular_posts(@date))
end