Skip to content

Commit c6c1607

Browse files
author
Chase Geigle
committed
Fix issue cpp-netlib#110 and issue cpp-netlib#168.
1 parent 4e0e198 commit c6c1607

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

boost/network/protocol/http/message/async_message.hpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,34 @@ namespace boost { namespace network { namespace http {
118118
}
119119

120120
string_type const body() const {
121-
return body_.get();
121+
string_type body;
122+
string_type partial_parsed = body_.get();
123+
124+
typename headers_range<basic_response<Tag> >::type transfer_encoding_range = headers().equal_range("Transfer-Encoding");
125+
if (!empty(transfer_encoding_range) && boost::iequals(boost::begin(transfer_encoding_range)->second, "chunked")) {
126+
typename string_type::iterator begin = partial_parsed.begin();
127+
string_type crlf = "\r\n";
128+
for (typename string_type::iterator iter = std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end());
129+
iter != partial_parsed.end();
130+
iter = std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end())) {
131+
string_type line(begin, iter);
132+
if (line.empty()) break;
133+
std::stringstream stream(line);
134+
int len;
135+
stream >> std::hex >> len;
136+
iter += 2;
137+
if (!len) break;
138+
if (len <= partial_parsed.end() - iter) {
139+
body.insert(body.end(), iter, iter + len);
140+
iter += len;
141+
}
142+
begin = iter;
143+
}
144+
} else {
145+
std::swap(body, partial_parsed);
146+
}
147+
148+
return body;
122149
}
123150

124151
void body(boost::shared_future<string_type> const & future) const {

0 commit comments

Comments
 (0)