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

Add functions to split URI query parts #281

Open
wants to merge 6 commits into
base: master
from

Conversation

@landesfeind
Copy link

@landesfeind landesfeind commented Dec 2, 2018

Hi,
this PR adds a function to parse the URI query into a HashMap to allow easier retrieval of the values plus some convenience functions. Finally, it is quite easy to just do:

let my_query_value = match uri.query_param_first("foo") {
   Some(value) => value,
   None => "my-default-value"
}

The code is provided as is and I hope it helps someone. Please be aware that I am relatively new to Rust and hope that the added tests ensure that I did not screw up totally ;-)
Best,
Manuel

@carllerche
Copy link
Collaborator

@carllerche carllerche commented Dec 12, 2018

Thanks for the work and posting this.

I agree that it would be nice to have a simple API for getting query parameters out. One difficulty is that http is attempting to be as opinionated as possible and there is no unopinionated way to parse query parameters. You'd probably want to do something like what the browser does, but how do you handle nested params, etc...

Given this, I'm not sure if this code should live in the http crate vs. a separate crate. Thoughts @seanmonstar ?

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

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.