-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Description
When using curl to upload large files (>1M) to a server written with cpp-httplib, curl adds the Expect: 100-continue header. After the server rejects the request by returning a non-100 status code and some data, curl blocks for 1 second after receiving the data and then fails with a broken pipe error.
Steps to Reproduce
-
Set up a server using cpp-httplib.
-
Use
curlto upload a file larger than 1M to the server. -
Observe the
--traceoutput fromcurl, which shows that it still sends data after handling the100-continueresponse.== Info: Done waiting for 100-continue => Send data, 65536 bytes (0x10000)
Expected Behavior
According to RFC 7231 section 5.1.1:
A server that responds with a final status code before reading the
entire message body SHOULD indicate in that response whether it
intends to close the connection or continue reading and discarding
the request message (see Section 6.6 of [RFC7230]).
The expected behavior is for the server to either:
- Read and discard the remaining request data, or
- Close the connection immediately with a
Connection: closeheader.
Current Behavior
Currently, cpp-httplib does not handle this scenario correctly. It neither reads and discards the remaining request data nor closes the connection immediately. Instead, it leaves the connection as-is and continues to respond with the Keep-Alive header for CPPHTTPLIB_KEEPALIVE_MAX_COUNT times if the client does not close the connection in the request header.
Attempted Solution
The following modification to the code at
Line 6706 in 548dfff
| default: return write_response(strm, close_connection, req, res); |
curl:
default:
connection_closed = true;
return write_response(strm, true, req, res);With this change, curl exits without the broken pipe error.
Additional Context
- Link to the relevant curl documentation: https://everything.curl.dev/http/post/expect100.html