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

fix #292 change get_args to return mutliple values per key #293

Closed
wants to merge 1 commit into from

Conversation

stuart-byma
Copy link
Contributor

Requirements for Contributing a Bug Fix

Identify the Bug

#292

Description of the Change

Change arg_map and arg_view_map to std::map<std::string, std::vector<std::string>> etc, so that multiple values per key can be returned.

Update an appropriate test case to check that the behavior is correct.

Alternate Designs

No alternate designs

Possible Drawbacks

Small change to user facing API.

Verification Process

Tests were updated to check that new code is correct.

Release Notes

  • Fixed a bug where http_request::get_args() only returned the last value for a given argument key. It now returns all values associated with a given key.

Update the full arguments processing test to make sure the new behavior
is as desired.
(*aa->arguments)[key] = value;
auto existing_iter = aa->arguments->find(key);
if (existing_iter != aa->arguments->end()) {
// Key exists, add value to collection instead of overwriting previous value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether the key exists or not, I think this if/else equivalent to just:

(*aa->arguments)[key].push_back(value);

@@ -298,7 +298,12 @@ class http_request {
* @param value The value assumed by the argument
**/
void set_arg(const std::string& key, const std::string& value) {
cache->unescaped_args[key] = value.substr(0, content_size_limit);
auto existing_iter = cache->unescaped_args.find(key);
if (existing_iter != cache->unescaped_args.end()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly I think this is also just cache->unescaped_args[key].push_back(value.substr(0, content_size_limit));, and below.

@@ -105,20 +105,31 @@ const http::header_view_map http_request::get_cookies() const {
}

std::string_view http_request::get_arg(std::string_view key) const {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since get_arg() now returns only the first matching item (which does keep the API the same), should there also be a get_args() method that returns a std::span<const std::string> or whatever type makes the least memory allocations? IIRC a span<const T> can be made from a vector<T> implicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik span is C++20, so this would require bumping the min version from 17.

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

Successfully merging this pull request may close these issues.

None yet

2 participants