File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,6 +159,9 @@ class DROGON_EXPORT HttpRequest
159159 */
160160 virtual void removeHeader (std::string key) = 0;
161161
162+ // Clear all HTTP headers
163+ virtual void clearHeaders () = 0;
164+
162165 // / Get the cookie string identified by the field parameter
163166 virtual const std::string &getCookie (const std::string &field) const = 0;
164167
Original file line number Diff line number Diff line change @@ -351,6 +351,11 @@ class HttpRequestImpl : public HttpRequest
351351 headers_.erase (lowerKey);
352352 }
353353
354+ void clearHeaders () override
355+ {
356+ headers_.clear ();
357+ }
358+
354359 const std::string &getHeader (std::string field) const override
355360 {
356361 std::transform (field.begin (),
Original file line number Diff line number Diff line change @@ -239,3 +239,22 @@ DROGON_TEST(AddHttpCorsHeaders)
239239 resp->addCorsHeaders (req);
240240 CHECK (resp->getHeader (" Access-Control-Allow-Credentials" ) == " true" );
241241}
242+
243+ DROGON_TEST (ClearHeaders)
244+ {
245+ auto req = HttpRequest::newHttpRequest ();
246+ // set a custom path to ensure it is not cleared
247+ req->setPath (" /api/test" );
248+ req->addHeader (" X-Test" , " value" );
249+ req->addHeader (" Authorization" , " Bearer token" );
250+
251+ CHECK (req->headers ().size () == 2 );
252+ CHECK (req->getHeader (" X-Test" ) == " value" );
253+ CHECK (req->getHeader (" Authorization" ) == " Bearer token" );
254+
255+ req->clearHeaders ();
256+
257+ CHECK (req->headers ().empty ());
258+ // verify path unchanged
259+ CHECK (req->path () == " /api/test" );
260+ }
You can’t perform that action at this time.
0 commit comments