Skip to content
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

HTTP::Request#headline raises InvalidURIError when path is equal to // #389

Closed
scarfacedeb opened this issue Jan 20, 2017 · 1 comment
Closed

Comments

@scarfacedeb
Copy link
Contributor

scarfacedeb commented Jan 20, 2017

I've encountered InvalidURIError error when dealing with the redirects to a location with // path. (e.g. https://google.com//).

After further investigation, I realized that HTTP doesn't allow to make a request to such urls at all.

The crux of the matter is HTTP::Request#headline method that uses Addressable::URI#omit method to get the path + query portion of the given url.

And while addressable allows to parse such urls http://google.com// and most of the methods work as expected, it fails with InvalidURIError when uri.omit(:authority) is called.

Relevant line in Addressable source code: https://github.com/sporkmonger/addressable/blob/8f4fee07243af0b788c625e59a9ca529489336d6/lib/addressable/uri.rb#L2427

Steps to reproduce

HTTP.get("https://google.com//")
#Addressable::URI::InvalidURIError: Cannot have a path with two leading slashes without anauthority set: '//'

Reproducing with Addressable directly:

# Parse url with // path
url = Addressable::URI.parse("https://google.com//")

# Check that it works as expected
url.path == "//"

# Try to remove authority
url.omit(:authority)  # raises InvalidURIError

I was going to submit this issue to the addressable repository at first, but after the consideration I think that it's primarily the bug in HTTP.

Because Addressable is following the spec that disallows path with two leading slashes without the authority.


Ruby version: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
Gem version: http (2.1.0) and addressable (2.5.0)

@ixti
Copy link
Member

ixti commented Dec 4, 2017

Hmm... @httprb/core I guess I agree. Probably we should "fix" this on our end. Something like:

uri = uri.path
uri += "?#{uri.query}" if uri.query
uri += "##{uri.framgent}" if uri.fragment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants