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
Six container getters on http_request now return `const ContainerType&`
aliasing impl-owned storage instead of copying maps/vectors on every
call:
- get_path_pieces() -> const std::vector<std::string>&
- get_headers() -> const http::header_view_map&
- get_footers() -> const http::header_view_map&
- get_cookies() -> const http::header_view_map&
- get_args() -> const http::arg_view_map&
- get_files() -> const std::map<std::string,
std::map<std::string,
http::file_info>>&
Implementation
--------------
http_request_impl carries six new mutable caches (one per getter):
* headers_cached_ / footers_cached_ / cookies_cached_ -- view-maps
populated lazily on the first call to get_headers/footers/cookies.
The new ensure_headerlike_cache(MHD_ValueKind) helper replaces
get_headerlike_values(), populating the matching slot once and
returning a const& on subsequent calls. The string_view keys/values
alias MHD-owned storage on the live-request path and the impl's
own headers_local/footers_local/cookies_local maps on the
test-request path -- both share the request lifetime.
* args_view_cached_ -- view-map built once from the pmr-backed
`unescaped_args` after populate_args(). The string_views alias the
pmr::strings owned by unescaped_args, same lifetime.
* path_pieces_public_ -- public-typed mirror of the existing
pmr-backed `path_pieces`. Two caches in lockstep: the pmr one stays
arena-friendly for any future internal consumer; the public one is
what get_path_pieces() returns by const&.
get_files() returns impl_->files_ directly (already the exact public
type, no extra cache); marked noexcept since the body is now a pure
member dereference.
Allocator note
--------------
The cached view-maps and path_pieces_public_ are default-allocator-
typed because the public API's container types are -- they cannot be
PMR without changing the public surface. First call therefore allocates
on the global heap; subsequent calls are O(1) and zero-allocating, a
strict win over v1 which paid the build cost on every call. This is
the trade-off PRD §3.6 anticipates and TASK-039 will measure.
Lifetime contract
-----------------
http_request.hpp gains a "Container reference lifetime contract"
section in the class-level docblock: the returned references and any
iterators / element references / string_view keys/values derived from
them remain valid until the http_request is destroyed (typically when
the handler invocation returns). This mirrors the TASK-016 string_view
contract.
Tests
-----
* test/unit/http_request_pimpl_test.cpp -- twelve compile-time asserts
added: six is_lvalue_reference_v assertions (matching the literal
acceptance criterion) plus six is_same_v assertions locking the
exact `const ContainerType&` return type. Drift back to by-value or
to a non-const reference fails compilation now.
* test/unit/create_test_request_test.cpp -- new
`getters_return_const_ref_stable` test verifying that two calls to
the same getter on a const http_request return the same address (the
cache reference is stable across calls).
Caller sweep
------------
Callers that took the return by value have been updated to bind by
const reference where the original semantics were read-only:
test/integ/basic.cpp (args_caching, footer_test_resource),
test/integ/file_upload.cpp (print_file_upload_resource render_POST/PUT
-- args_view bound by ref; the `files = req.get_files()` copies are
deliberate and now copy-from-const& with comments explaining intent),
test/unit/create_test_request_test.cpp (build_headers /
build_footers_cookies / build_path_pieces), and
examples/args_processing.cpp.
Known pre-existing failure unrelated to TASK-017:
test/unit/create_test_request_test::method_uppercase. It expects
set_method() to uppercase its argument; commit a2afe2b removed that
uppercasing, and the test was added in 755ecc1 after that, so it has
been failing on feature/v2.0 since well before this task. Not fixed
here.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments