Add streamed response callback with chunked transfer support#1151
Open
Kirpatik wants to merge 1 commit intoCrowCpp:masterfrom
Open
Add streamed response callback with chunked transfer support#1151Kirpatik wants to merge 1 commit intoCrowCpp:masterfrom
Kirpatik wants to merge 1 commit intoCrowCpp:masterfrom
Conversation
Member
|
Sounds great. :) |
Member
|
The current implementation would block one working thread per running client request, right? |
Author
Yes. do_write_streamed() is called synchronously from complete_request() and performs blocking asio::write calls in a loop, so one worker thread stays occupied by that request until the stream finishes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds explicit streamed response sending via callback, including support for unknown total size responses.
Added API
set_streamed_body(std::function<size_t(void*, size_t)> reader, size_t content_length, std::string content_type = "", size_t chunk_size = 16 * 1024)set_streamed_body(std::function<size_t(void*, size_t)> reader, std::string content_type = "", size_t chunk_size = 16 * 1024)Callback contract:
(buffer, max_size)max_sizebytes0to indicate end-of-streamBehavior
Transfer-Encoding: chunked.chunk_sizeis configurable per response; default remains 16KB.HEADwith known-length streamed responses sends headers only and preservesContent-Length.Implementation Notes
Connection::do_write_streamed().Tests
Added/updated tests:
streamed_responsestreamed_response_unknown_size_chunkedstreamed_response_unknown_size_http10_fallbackstreamed_response_head_known_length_no_body