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

How to get the full url? #250

Open
szabgab opened this issue Dec 13, 2023 · 3 comments
Open

How to get the full url? #250

szabgab opened this issue Dec 13, 2023 · 3 comments

Comments

@szabgab
Copy link

szabgab commented Dec 13, 2023

If I access the server as http://localhost:5000/echo?text=Hello%20World the request.url() returns only /echo?text=Hello%20World.
Is there a method to get the full original URL?

If not then I think it would be useful to either change url to return that, or have another method that would return the full url.

@bradfier
Copy link
Member

To construct the full address you need to get the Host header from the request and prepend it to the output of url(). This won't tell you if the request was made over HTTP or HTTPS though.

The reason url() doesn't do this by default is that you need to parse the full header section to be able to get that information, and we should be able to route without doing so.

@szabgab
Copy link
Author

szabgab commented Dec 13, 2023

Thanks. As far as I can see in order to parse the Url I need to supply a full URL including the protocol and the hostname to the url crate. Is there a better way to get the parameters sent via the QUERY_STRING?

@bradfier
Copy link
Member

The 'resource' part of the HTTP request is just a string, so you can take the string from url(), split it on ? and that will give you a string that is a & separated list of URLEncoded query parameters.

Tiny-http doesn't do this for you, it's typically implemented a layer up in the router for something like Rouille.

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