Skip to content

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

Closed
stuart-byma wants to merge 1 commit intoetr:masterfrom
stuart-byma:argHandling
Closed

fix #292 change get_args to return mutliple values per key#293
stuart-byma wants to merge 1 commit intoetr:masterfrom
stuart-byma:argHandling

Conversation

@stuart-byma
Copy link
Copy Markdown
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.
Copy link
Copy Markdown

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);

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()) {
Copy link
Copy Markdown

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 {
Copy link
Copy Markdown

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
Copy Markdown
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.

2 participants