-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: allow non -chunked streams w/o Content-Length header #2339
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
base: master
Are you sure you want to change the base?
Conversation
|
@stefan-tb Thanks for the pull request. Could you please add the unit test in |
|
@yhirose: wow. 🥇 for your response time. Honestly. Thanks |
|
@stefan-tb I just had the Copilot review this pull request, and here is the summary. Could you take a look at this potential problem, too?
I have already fixed the same issue on the server side before. You can see the code in the following locations. Payload Max Length ExceedLimit: Lines 9126 to 9131 in fbec2a3
Lines 8244 to 8507 in fbec2a3
Decompressed Size Exceeds Limit: Lines 9016 to 9023 in fbec2a3
Line 14240 in fbec2a3
Thanks! |
|
My changes only apply to non-chunked, client-side streaming scenarios. Calling |
Plain (non chunked) HTTP bodies from server responses without a
Content-Lengthheader can't be read at client side.Example:
That's because in the case of the missing header, the method
ClientImpl::open_streamdoesn't setBodyReader::content_lengthand the value remains entirely untouched (default value 0):cpp-httplib/httplib.h
Lines 10448 to 10453 in fbec2a3
Therefore consecutive tests in
BodyReader::read, like this one:cpp-httplib/httplib.h
Lines 8128 to 8131 in fbec2a3
will immediately set
eofand return 0 before even trying to read any actual data.This PR is introducing another field
bool has_content_length(std::optionalis not C++11 as far as I know) to track ifBodyReader::content_lengthhas been set. If not, the related tests are skipped. Please note that theeolflag will still be properly set when a read from the underlying stream returns 0.I am new to this code base, this is a best effort commit. I tried to keep things as local as possible. Sorry in advance if I am violating style / approaches.