forked from glynos/cpp-netlib
-
Notifications
You must be signed in to change notification settings - Fork 425
Closed
Description
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!
Metadata
Metadata
Assignees
Labels
No labels