etr / libhttpserver

C++ library for creating an embedded Rest HTTP server (and more)
GNU Lesser General Public License v2.1
882 stars 184 forks source link

[BUG] deferred_response never sends content string passed to constructor #331

Open jcphill opened 1 year ago

jcphill commented 1 year ago

Prerequisites

Description

The deferred_response constructor includes a const std::string& content = "" parameter that is documented as:

Besides the callback, optionally, you can provide a content parameter that sets the initial message sent immediately to the client.

The content parameter is passed to the base class string_response constructor where it is assigned to the content member but never actually consumed because string_response::get_raw_response() is never called.

This behavior might appear to have been removed by https://github.com/etr/libhttpserver/commit/ed0841d177d88dada6e21e4dd5c36f8b670c1ee0 in #145, but it likely didn't work even in https://github.com/etr/libhttpserver/commit/eea93bdf45c42ffbb487f06385ab6a7647bc0a5f because get_raw_response() is a virtual function.

The tests don't expect the content parameter to be sent either: https://github.com/etr/libhttpserver/blob/d249ba682441dbb979146482aff01a7073ed165a/test/integ/deferred.cpp#L164

At this point in the interest of bug compatibility maybe just change the parameter name from "content" to "unused" and fix the docs.

Steps to Reproduce

Send a deferred_response with a non-empty content argument such as https://github.com/etr/libhttpserver/blob/d249ba682441dbb979146482aff01a7073ed165a/test/integ/deferred.cpp#L103

Expected behavior: Content argument is transmitted.

Actual behavior: Content argument is ignored.

Reproduces how often: 100%

Versions

Additional Information