How can you refine HTTP::Headers.normalize_header?

80 Views Asked by At

normalize_header in HTTP::headers turns underscores into dashes (https://github.com/httprb/http/issues/337). This isn't correct in some cases. I can easily monkey patch this. But I was trying to figure out how to use a refinement to narrow the scope of the modification.

require "http"

module NormalizeHeaderPatch
  refine HTTP::Headers do
    def normalize_header(name)
      puts "refined normalize_header"
      name
    end
  end
end

using NormalizeHeaderPatch
auth_res = HTTP.headers(
  "client_id" => "client_id"
).get("https://www.google.com")

But that doesn't work. My gut is that I have missed something with the refinement not being activated once we are in the scope that ends up calling normalize_header but I don't know how to arrange for that to work.

0

There are 0 best solutions below