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

not-a-base on host:port string #588

Open
genbattle opened this issue Feb 22, 2020 · 1 comment
Open

not-a-base on host:port string #588

genbattle opened this issue Feb 22, 2020 · 1 comment

Comments

@genbattle
Copy link

genbattle commented Feb 22, 2020

I'm using the URL library to parse a Host header, and when my application is running on localhost the value that comes out of the header is localhost:3000 (for example).

This value is parsed into a Url but comes out with cannot_be_a_base() as true, so I can't join it.

With url 2.1.1 I can't call set_scheme on the parsed URL either, but that seems to be related to another regression that multiple people have raised in #577. With 2.1.0 I can call set_scheme on the parsed URL but it still comes out as cannot_be_a_base().

I worked around this by prepending "http://" onto whatever comes out of the Host header. I see this library also has a Host struct, but I don't see any way to convert a Host into a Url. I guess what' I'm looking for is a better way to build a URL from parts.

@genbattle genbattle changed the title not-a-base on base:port string not-a-base on host:port string Feb 22, 2020
@tmccombs
Copy link
Contributor

I see this library also has a Host struct, but I don't see any way to convert a Host into a Url

you would need a scheme to convert it to a valid URL. But it does seem like there should be an API to build a url from parts rather than having to create a string and parse it. Maybe an api that allows you to do something like:

let url = Url::builder("http").host(host).port(port)

I'm using the URL library to parse a Host header

The Host header isn't a URL. It is just the host, optionally followed by the port.

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