@@ -85,7 +85,31 @@ struct http_request_impl_deleter {
8585} // namespace detail
8686
8787/* *
88- * Class representing an abstraction for an Http Request. It is used from classes using these apis to receive information through http protocol.
88+ * Class representing an abstraction for an Http Request. It is used from
89+ * classes using these APIs to receive information through the HTTP protocol.
90+ *
91+ * ### string_view lifetime contract (TASK-016)
92+ *
93+ * Several getter methods return `std::string_view` rather than `std::string`
94+ * for zero-copy access to request data that lives in a per-connection arena.
95+ * **All `std::string_view` values returned by this class are only valid
96+ * within the handler's call frame.** They alias arena-backed storage that is
97+ * released by the request-completion callback once the handler returns.
98+ *
99+ * Concretely: do NOT store a `std::string_view` from any getter in a
100+ * variable with a lifetime that outlasts the handler invocation. If you
101+ * need the data beyond the handler, copy it into a `std::string`:
102+ *
103+ * // Safe: copy before the handler returns.
104+ * std::string username_copy(request.get_user());
105+ *
106+ * // UNSAFE: the view is dangling after the handler returns.
107+ * std::string_view view = request.get_user(); // captured past return!
108+ *
109+ * Getters affected: get_arg_flat(), get_querystring(), get_user(),
110+ * get_pass(), get_digested_user(), get_header(), get_footer(),
111+ * get_cookie(), get_requestor().
112+ * (security-reviewer-iter1-1, CWE-416 Use After Free.)
89113**/
90114class http_request {
91115 public:
@@ -95,14 +119,18 @@ class http_request {
95119 /* *
96120 * Method used to get the username eventually passed through basic authentication.
97121 * @return string representation of the username.
122+ * @note The returned view is only valid within the handler's call frame.
123+ * Copy into std::string if the value must outlast the handler.
98124 **/
99125 std::string_view get_user () const ;
100126#endif // HAVE_BAUTH
101127
102128#ifdef HAVE_DAUTH
103129 /* *
104- * Method used to get the username extracted from a digest authentication
105- * @return the username
130+ * Method used to get the username extracted from a digest authentication.
131+ * @return the username.
132+ * @note The returned view is only valid within the handler's call frame.
133+ * Copy into std::string if the value must outlast the handler.
106134 **/
107135 std::string_view get_digested_user () const ;
108136#endif // HAVE_DAUTH
@@ -111,6 +139,8 @@ class http_request {
111139 /* *
112140 * Method used to get the password eventually passed through basic authentication.
113141 * @return string representation of the password.
142+ * @note The returned view is only valid within the handler's call frame.
143+ * Copy into std::string if the value must outlast the handler.
114144 **/
115145 std::string_view get_pass () const ;
116146#endif // HAVE_BAUTH
@@ -196,15 +226,20 @@ class http_request {
196226 * Method used to get a specific header passed with the request.
197227 * @param key the specific header to get the value from
198228 * @return the value of the header.
229+ * @note The returned view is only valid within the handler's call frame.
199230 **/
200231 std::string_view get_header (std::string_view key) const ;
201232
233+ /* *
234+ * @note The returned view is only valid within the handler's call frame.
235+ **/
202236 std::string_view get_cookie (std::string_view key) const ;
203237
204238 /* *
205239 * Method used to get a specific footer passed with the request.
206240 * @param key the specific footer to get the value from
207241 * @return the value of the footer.
242+ * @note The returned view is only valid within the handler's call frame.
208243 **/
209244 std::string_view get_footer (std::string_view key) const ;
210245
@@ -220,6 +255,8 @@ class http_request {
220255 * If the arg key has more than one value, only one is returned.
221256 * @param key the specific argument to get the value from
222257 * @return the value of the arg.
258+ * @note The returned view is only valid within the handler's call frame.
259+ * Copy into std::string if the value must outlast the handler.
223260 **/
224261 std::string_view get_arg_flat (std::string_view key) const ;
225262
@@ -239,8 +276,9 @@ class http_request {
239276 return content.size () >= content_size_limit;
240277 }
241278 /* *
242- * Method used to get the content of the query string..
243- * @return the query string in string representation
279+ * Method used to get the content of the query string.
280+ * @return the query string in string representation.
281+ * @note The returned view is only valid within the handler's call frame.
244282 **/
245283 std::string_view get_querystring () const ;
246284
@@ -316,7 +354,8 @@ class http_request {
316354
317355 /* *
318356 * Method used to get the requestor.
319- * @return the requestor
357+ * @return the requestor (IP address string).
358+ * @note The returned view is only valid within the handler's call frame.
320359 **/
321360 std::string_view get_requestor () const ;
322361
0 commit comments