-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect handling of Expect: 100-continue
during large file uploads
#1808
Comments
Update: The latest RFC 9110 section 10.1.1 says |
@solarispika thanks for the report. Could you send a pull request that you suggests and a unit test in |
Sure! I'll take some time to see how I can add some proper tests. |
@yhirose I have difficulty where To comprehensively test the server implementation, the client should also support the required behavior as per the specification. However, I don't have enough time to implement the necessary changes in Instead, I propose using an external tool or library that already supports the Please let me know if you have any concerns or suggestions regarding this proposed approach. |
@solarispika sorry for the late reply.
No problem. You can just focus on the server-side changes. |
How do I test this to see the broken behaviour? But it appears to work fine, where "toupload" is an 8MB+ file. |
@solarispika could you replay to the @paulharris's comment? |
@paulharris You need to setup 100-continue handler to reject uploads. svr.set_expect_100_continue_handler([](Request const& req, Response& res) {
res.status = 400;
res.set_content("{\"error\": \"You Shall Not Upload!!!!\"}", "application/json; charset=utf-8");
return 400;
}); |
Are you planning to implement it (only server-side is ok) anytime soon? |
@yhirose |
@solarispika The code looks good to me. I fixed some build problems with Makefile on GitHub Actions workflow. Thanks for your fine contribution! |
Description
When using
curl
to upload large files (>1M) to a server written with cpp-httplib,curl
adds theExpect: 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
curl
to upload a file larger than 1M to the server.Observe the
--trace
output fromcurl
, which shows that it still sends data after handling the100-continue
response.Expected Behavior
According to RFC 7231 section 5.1.1:
The expected behavior is for the server to either:
Connection: close
header.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 forCPPHTTPLIB_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
cpp-httplib/httplib.h
Line 6706 in 548dfff
curl
:With this change, curl exits without the broken pipe error.
Additional Context
The text was updated successfully, but these errors were encountered: