You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use string_view in API methods where applicable (#288)
* Issue #286: use string_view in API methods where applicable
This change reduces required copying of immutable data primarily in the
HTTP request API. Methods returning strings now return string_view to
avoid copying immutable data from the underlying MHD impl.
get_*s methods still return a std::map which must be allocated
and constructed, but does not copy underlying strings.
Fix a few instances of these method calls in the code base.
Introduce some type aliases for maps from string_view to string_view,
string to string to reduce code verbosity.
Overload the comparator operator()s as required.
Provide overloads for dump_*_map functions and a template impl to avoid
code duplication.
Bump C++ version to 17 required to use string_view. Remove CI
configurations using ancient compilers that don't support string_view
or C++17
* Issue #286: use string_view in API methods where applicable
This change reduces required copying of immutable data primarily in the
HTTP request API. Methods returning strings now return string_view to
avoid copying immutable data from the underlying MHD impl.
get_*s methods still return a std::map which must be allocated
and constructed, but does not copy underlying strings.
Fix a few instances of these method calls in the code base.
Introduce some type aliases for maps from string_view to string_view,
string to string to reduce code verbosity.
Overload the comparator operator()s as required.
Provide overloads for dump_*_map functions and a template impl to avoid
code duplication.
Bump C++ version to 17 required to use string_view. Remove CI
configurations using ancient compilers that don't support string_view
or C++17
* Issue #286: use string_view in API methods where applicable
This change reduces required copying of immutable data primarily in the
HTTP request API. Methods returning strings now return string_view to
avoid copying immutable data from the underlying MHD impl.
get_*s methods still return a std::map which must be allocated
and constructed, but does not copy underlying strings.
Fix a few instances of these method calls in the code base.
Introduce some type aliases for maps from string_view to string_view,
string to string to reduce code verbosity.
Overload the comparator operator()s as required.
Bump C++ version to 17 required to use string_view. Remove CI
configurations using ancient compilers that don't support string_view
or C++17
* remove accidentally added line of code
* fix data scope issue
In the file upload test, it was saving the arg_view_map from the
request, which went out of scope, leaving dangling refs.
Fix by making a deep copy.
* undo change from arg_map to arg_view_map
Because build_request_args makes a temp copy of underlying data and
mutates it, it is not feasible currently to return a view over that data.
* fix readme after changing get_args signature
* cache transformed data to return views over data
Add a data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
* cache transformed data to return views over data
Add a data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
* cache transformed data to return views over data
Add a data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
* cache transformed data to return views over data
Add a data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
* cache transformed data to return views over data
Add a http_request_data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
Remove the existing http_request::args member, use the cache instead.
Make the http_request class move-only.
* cache transformed data to return views over data
Add a http_request_data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
Remove the existing http_request::args member, use the cache instead.
Make the http_request class move-only.
* cache transformed data to return views over data
Add a http_request_data_cache type to the http request type, and a unique_ptr
instance member. This allows caching of transformed and/or copied data
from MHD, while preserving const-ness of all accessor methods.
Change all applicable methods to string_view, fix a few call sites.
Remove the existing http_request::args member, use the cache instead.
Make the http_request class move-only.
@@ -559,13 +561,13 @@ The `http_request` class has a set of methods you will have access to when imple
559
561
*_**const std::vector\<std::string\>&** get_path_pieces() **const**:_ Returns the components of the path requested by the HTTP client (each piece of the path split by `'/'`.
560
562
*_**const std::string&** get_path_piece(int index) **const**:_ Returns one piece of the path requested by the HTTP client. The piece is selected through the `index` parameter (0-indexed).
561
563
*_**const std::string&** get_method() **const**:_ Returns the method requested by the HTTP client.
562
-
*_**const std::string** get_header(**const std::string&** key) **const**:_ Returns the header with name equal to `key` if present in the HTTP request. Returns an `empty string` otherwise.
563
-
*_**const std::string** get_cookie(**const std::string&** key) **const**:_ Returns the cookie with name equal to `key` if present in the HTTP request. Returns an `empty string` otherwise.
564
-
*_**const std::string** get_footer(**const std::string&** key) **const**:_ Returns the footer with name equal to `key` if present in the HTTP request (only for http 1.1 chunked encodings). Returns an `empty string` otherwise.
565
-
*_**const std::string** get_arg(**const std::string&** key) **const**:_ Returns the argument with name equal to `key` if present in the HTTP request. Arguments can be (1) querystring parameters, (2) path argument (in case of parametric endpoint, (3) parameters parsed from the HTTP request body if the body is in `application/x-www-form-urlencoded` or `multipart/form-data` formats and the postprocessor is enabled in the webserver (enabled by default).
566
-
*_**const std::map<std::string, std::string, http::header_comparator>** get_headers() **const**:_ Returns a map containing all the headers present in the HTTP request.
567
-
*_**const std::map<std::string, std::string, http::header_comparator>** get_cookies() **const**:_ Returns a map containing all the cookies present in the HTTP request.
568
-
*_**const std::map<std::string, std::string, http::header_comparator>** get_footers() **const**:_ Returns a map containing all the footers present in the HTTP request (only for http 1.1 chunked encodings).
564
+
*_**std::string_view** get_header(**std::string_view** key) **const**:_ Returns the header with name equal to `key` if present in the HTTP request. Returns an `empty string` otherwise.
565
+
*_**std::string_view** get_cookie(**std::string_view** key) **const**:_ Returns the cookie with name equal to `key` if present in the HTTP request. Returns an `empty string` otherwise.
566
+
*_**std::string_view** get_footer(**std::string_view** key) **const**:_ Returns the footer with name equal to `key` if present in the HTTP request (only for http 1.1 chunked encodings). Returns an `empty string` otherwise.
567
+
*_**std::string_view** get_arg(**std::string_view** key) **const**:_ Returns the argument with name equal to `key` if present in the HTTP request. Arguments can be (1) querystring parameters, (2) path argument (in case of parametric endpoint, (3) parameters parsed from the HTTP request body if the body is in `application/x-www-form-urlencoded` or `multipart/form-data` formats and the postprocessor is enabled in the webserver (enabled by default).
568
+
*_**const std::map<std::string_view, std::string_view, http::header_comparator>** get_headers() **const**:_ Returns a map containing all the headers present in the HTTP request.
569
+
*_**const std::map<std::string_view, std::string_view, http::header_comparator>** get_cookies() **const**:_ Returns a map containing all the cookies present in the HTTP request.
570
+
*_**const std::map<std::string_view, std::string_view, http::header_comparator>** get_footers() **const**:_ Returns a map containing all the footers present in the HTTP request (only for http 1.1 chunked encodings).
569
571
*_**const std::map<std::string, std::string, http::arg_comparator>** get_args() **const**:_ Returns all the arguments present in the HTTP request. Arguments can be (1) querystring parameters, (2) path argument (in case of parametric endpoint, (3) parameters parsed from the HTTP request body if the body is in `application/x-www-form-urlencoded` or `multipart/form-data` formats and the postprocessor is enabled in the webserver (enabled by default).
570
572
*_**const std::map<std::string, std::map<std::string, http::file_info>>** get_files() **const**:_ Returns information about all the uploaded files (if the files are stored to disk). This information includes the key (as identifier of the outer map), the original file name (as identifier of the inner map) and a class `file_info`, which includes the size of the file and the path to the file in the file system.
571
573
*_**const std::string&** get_content() **const**:_ Returns the body of the HTTP request.
@@ -597,7 +599,7 @@ Details on the `http::file_info` structure.
0 commit comments