Allow calling Response::send multiple times: copy the buffer before async_write
This commit is contained in:
parent
d59b7c234c
commit
6b91839cb6
2 changed files with 32 additions and 1 deletions
|
|
@ -69,6 +69,20 @@ int main() {
|
|||
assert(request->remote_endpoint_port() != 0);
|
||||
};
|
||||
|
||||
server.resource["^/string/dup$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
|
||||
auto content = request->content.string();
|
||||
|
||||
// Send content twice, before it has a chance to be written to the socket.
|
||||
*response << "HTTP/1.1 200 OK\r\nContent-Length: " << (content.length() * 2) << "\r\n\r\n"
|
||||
<< content;
|
||||
response->send();
|
||||
*response << content;
|
||||
response->send();
|
||||
|
||||
assert(!request->remote_endpoint_address().empty());
|
||||
assert(request->remote_endpoint_port() != 0);
|
||||
};
|
||||
|
||||
server.resource["^/string2$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
|
||||
response->write(request->content.string());
|
||||
};
|
||||
|
|
@ -202,6 +216,15 @@ int main() {
|
|||
assert(output.str() == "A string");
|
||||
}
|
||||
|
||||
{
|
||||
// Test rapid calls to Response::send
|
||||
stringstream output;
|
||||
stringstream content("A string\n");
|
||||
auto r = client.request("POST", "/string/dup", content);
|
||||
output << r->content.rdbuf();
|
||||
assert(output.str() == "A string\nA string\n");
|
||||
}
|
||||
|
||||
{
|
||||
stringstream output;
|
||||
auto r = client.request("GET", "/info", "", {{"Test Parameter", "test value"}});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue