The Wayback Machine - https://web.archive.org/web/20210112002832/https://github.com/cpp-netlib/cpp-netlib/issues/827
Skip to content
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

Streaming API does not allow access to the HTTP status or the headers from the callback #827

Open
igorpeshansky opened this issue Mar 1, 2018 · 2 comments

Comments

@igorpeshansky
Copy link

@igorpeshansky igorpeshansky commented Mar 1, 2018

The current streaming API takes a callback function with two parameters:

  typedef function<void(boost::iterator_range<char const*> const&,
                        system::error_code const&)> body_callback_function_type;

This means that from within the body handler, there is no way to know what the HTTP status code was for the underlying request or what the headers were (most importantly the "Transfer-Encoding" header), even though the status code and the headers are parsed before the callback is invoked.

One workaround is to use the callback to simply assemble the body bytes, and then actually parse it after the request completes. This, however, won't work for hanging gets, where the data is coming in incrementally.

I'd like to augment the API to allow the callback to access the underlying http_async_protocol_handler fields (including the promises and is_chunk_encoding), most likely via the underlying response object. There is a way to make it backward compatible by overloading on a 2-parameter callback.

@deanberris, would you entertain a PR with such a change?

@umennel
Copy link

@umennel umennel commented Mar 5, 2018

Hi @igorpeshansky,
Async client support for chunked transfer encoding has been added to the master branch. See #720.
You still have to set the remove_chunk_markers option to get rid of the encoding bits enclosing each chunk. I pushed it to the master branch only because it is rather a large change.
If I knew in advance that there were still so many commits going into the 0.13 release, I would have pushed to 0.13 branch as well.

@deanberris
Copy link
Member

@deanberris deanberris commented Mar 6, 2018

Hi @igorpeshansky -- Yes, please send a PR through for an overload of the streaming body handler.

@umennel -- If you can get the chunked transfer encoding from master cherry-picked and/or ported to 0.13-release, then that would be great too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.