Skip to content

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

Open

Description

@igorpeshansky

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?

Activity

  1. umennel commented on Mar 5, 2018

    @umennel

    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.

  2. deanberris commented on Mar 6, 2018

    @deanberris
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions