Skip to content

fix http client body content #760

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

Merged

Conversation

chenzhaoyu
Copy link

@chenzhaoyu chenzhaoyu commented May 17, 2017

This is a bug,introduced by my last PR #713 , I'm very sorry!!
partial_parsed buffer will append part buffer twice in function parse_body and handle_received_data.
eg.

void request(std::string url)
{
    client::options options;
    options.remove_chunk_markers(true);
    client::request request_(url);
    request_ << header("Connection", "close");
    client client_(options);
    client::response response_ = client_.get(request_);
    std::string body_ = body(response_);
    printf("body len : %d\n", body_.length());
    printf("body  : %s\n", body_.c_str());
}

int main()
{
    request("http://www.google.com.cn");
    return 0;
}

cpp-netlib master output:
[irteam@dev-chenzhaoyu1.ncl cpplibtest]$ ./net_lib_client 
body len : 436
body  : <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.cn/">here</A>.
</BODY></HTML>
HTTP/1.1 301 Moved Permanently
Location: http://www.google.cn/
Content-Type: text/html; charset=UTF-8
Date: Wed, 17 May 2017 06:00:28 GMT
Expires: Fri, 16 Jun 2017 06:00:28 GMT
Cache-Control: public, max-age=25920
net_lib_client: /usr/local/include/boost/network/protocol/http/client/connection/async_normal.hpp:89: boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator> boost::network::http::impl::chunk_encoding_parser<boost::network::http::tags::http_async_8bit_udp_resolve>::operator()(const boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator> &) [Tag = boost::network::http::tags::http_async_8bit_udp_resolve]: Assertion `*iter == '\r'' failed.
Aborted

fixed output:
[irteam@dev-chenzhaoyu1.ncl cpplibtest]$ ./net_lib_client 
body len : 218
body  : <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.cn/">here</A>.
</BODY></HTML>

Copy link
Member

@deanberris deanberris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deanberris deanberris merged commit 092cd57 into cpp-netlib:master May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants