-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Rack::Headers to avoid deprecation warning about Rack 3 #240
Conversation
Thanks, @3UR for updating the code. Background: The Rack::Headers class was introduced in Rack rack/rack@79328de in 3.0. Blocker: https://github.com/savonrb/httpi/blob/master/httpi.gemspec#L24 And, more context to that blocker: savonrb/savon#992 |
Thanks @3UR and @olleolleolle - correct, this can't go in as-is. This is unlikely to go in at all, since this is a major breaking change that affects a public API method, and we're focused on maintenance only at the moment - see also #238 |
Couldn't we check the Rack version and use Rack::Utils::HeaderHash or Rack::Headers accordingly? |
@dorianmarie we could, but I disagree with that design choice: A library’s public API should not depend on the version of a transitive dependency. A change in API should be a change in version. |
so how can we silence this Rack::Utils::HeaderHash is deprecated warning |
presumably you could
# config/initializers/httpi.rb
# use rack 3.x interface to silence a warning
module HTTPI
class Response
def initialize(code, headers, body)
self.code = code.to_i
self.headers = Rack::Headers.new(headers)
self.raw_body = body
end
end
class Request
def headers
@headers ||= Rack::Headers.new
end
end
end |
Thank you @pcai Rails.logger.warn "Rewrote Httpi due to Rack::Utils::HeaderHash.new being deprecated https://github.com/rack/rack/blob/main/UPGRADE-GUIDE.md?plain=1 "
module HTTPI
class Response
def initialize(code, headers, body)
self.code = code.to_i
self.headers = !headers.is_a?(Hash) ? Rack::Headers.new.merge!(headers) : headers
self.raw_body = body
end
end
class Request
def headers
@headers ||= Rack::Headers.new
end
def headers=(headers)
@headers = Rack::Headers.new.merge!(headers)
end
end
end` |
The problem lies in |
It seems to be incorrect this version @3UR and @pcai as Rack::Headers.new does not accept a hash as an argument see below Rack::Headers.new(headers) => {} vs Rack::Utils::HeaderHash.new(headers) => {
"Content-Type" => "application/json",
"Authorization" => "Bearer your_token_here",
}
This would be more correct
Rack::Headers.new.merge!(headers) |
Thanks everyone for your contributions. I took some time to investigate and this is now fixed in 56cd67b which ended up being relatively minor overall. I couldn't use this PR - as others have pointed out, the code isn't correct, and it doesnt account for tests and other dependencies that need updating (namely puma 6.x) |
also @Slotos re:
I agree that this is a mistake in the initial API design. But there is no turning back the clock on this one unfortunately. |
This resolves #239