sparklemotion/http-cookie

URI::InvalidURIError

shlima opened this issue · 0 comments

Can you pleas detach URI calls into a configurable proc or adapter, as some sites has UTF-8 (non standard) chars inside URL

Som my temporary fix is:

invalid_uri_fix = Module.new do
  def URI(url)
    encoded_url = URI.encode(url.to_s)
    URI.parse(encoded_url)
  end
end

HTTP::CookieJar.prepend(invalid_uri_fix)
HTTP::Cookie.extend(invalid_uri_fix)

The perfect solution i see will be the HTTP::Cookie.default_uri_parser accessor:

# default
HTTP::Cookie.default_uri_parser ->(value) do
  URI.parse(value) 
end

# user
HTTP::Cookie.default_uri_parser ->(value) do
  Addressable::URI.parse(value)
end