← 输入框|github.com|刷新
Skip to content

Reusing the response object #772

Closed
Closed

Description

@maingoh

I am implementing the follow_redirects using the async_client and when I reuse the same response object, the body is updated but not the headers.

Sample:

int main() {
    std::string url = "http://google.com";

    async_client::options options;
    options
       .follow_redirects(true)
       .cache_resolved(true)
       .always_verify_peer(false)
       ;

    async_client client(options);

    async_client::request req(url);

    auto response = client.get(req));

    while (!ready(response));

    // we get the expected headers and body
    auto hdrs = headers(response);

    for (auto &h : hdrs) {
        LOG(INFO) << h.first << ": " << h.second;
    }

    LOG(INFO) << body(response);

    LOG(INFO) << "-----------------";

    req.uri("http://example.com"); // changing the url

    response = client.get(req));

    while (!ready(response));

    // here the headers are the same as the previous response, they should be those from example.com
    auto hdrs2 = headers(response);

    for (auto &h : hdrs2) {
        LOG(INFO) << h.first << ": " << h.second;
    }

    // the body is the body of example.com
    LOG(INFO) << body(response);
}

I tried the swap method without success.
Weirdly I manage to make it working using smart_ptr like this :

response.reset(new async_client::response(client.get(req)));

Is there an explication or is it a bug ? If this is normal it should probably be explained in the documentation.

Also I had a similar problem with the request object (operator= didn't work), but using the swap method I made it working.

Thanks!

Activity

  1. deanberris commented on Aug 1, 2017

    @deanberris
    Member

    What version of the library are you using?

    If this is the latest in GitHub or in 0.13-devel this should be fixed (and it's a bug).

  2. maingoh commented on Aug 2, 2017

    @maingoh
    Author

    I am using the branch 0.13-release (I don't see any 0.13-devel). I install the library this way:

    git clone https://github.com/cpp-netlib/cpp-netlib.git
    cd cpp-netlib
    git checkout 0.13-release
    git submodule update --init
    
    cmake -D BUILD_SHARED_LIBS=ON .
    make install -j 6
    

    Also it seems that it generates the libraries sufixed by .so.0.12.0. Is it a problem with my installation or you just didn't change the version number yet ?

  3. deanberris commented on Aug 2, 2017

    @deanberris
    Member

    Yeah, we haven't changed the version number in the branch yet. Can you send a pull request to fix that?

  4. maingoh commented on Aug 2, 2017

    @maingoh
    Author

    I'll try. Not sure what is the bug, but I will try to investigate If I find the time.

  5. tex commented on Nov 20, 2017

    @tex

    I confirm the bug is here on 0.13-release branch.

  6. deanberris commented on Nov 21, 2017

    @deanberris
    Member

    Thanks @tex -- apologies for the delay here. I've merged the PR to fix it too, sorry I've been traveling around that time and missed the notification on the pull request. This should make it into an rc1 for 0.13.0 which I'll try to get to sometime this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions