Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7e3c10

Browse files
committed
Merge pull request#216 from skystrife/master
Fix issues#110 and#168.
2 parents5ac69cb +bd90c39 commita7e3c10

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

‎http/src/network/protocol/http/response/response.ipp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#ifndef NETWORK_PROTOCOL_HTTP_RESPONSE_RESPONSE_IPP_20111206
88
#defineNETWORK_PROTOCOL_HTTP_RESPONSE_RESPONSE_IPP_20111206
99

10+
#include<boost/algorithm/string/predicate.hpp>
1011
#include<network/protocol/http/response/response.hpp>
12+
13+
#include<algorithm>
1114
#include<set>
15+
#include<sstream>
1216

1317
namespacenetwork {
1418
namespacehttp {
@@ -91,7 +95,23 @@ struct response_pimpl {
9195
voidget_headers(
9296
std::stringconst& name,
9397
std::function<void(std::stringconst&, std::stringconst&)> inserter) {
94-
/* FIXME: Do something!*/
98+
if (removed_headers_.find(name) != removed_headers_.end())
99+
return;
100+
101+
std::pair<std::multimap<std::string, std::string>::const_iterator,
102+
std::multimap<std::string, std::string>::const_iterator>
103+
range;
104+
if (!headers_future_.valid()) {
105+
range = added_headers_.equal_range(name);
106+
}else {
107+
std::multimap<std::string, std::string>const& headers_ =
108+
headers_future_.get();
109+
range = headers_.equal_range(name);
110+
}
111+
112+
for (auto it = range.first; it != range.second; ++it) {
113+
inserter(it->first, it->second);
114+
}
95115
}
96116
voidget_headers(
97117
std::function<bool(std::stringconst&, std::stringconst&)> predicate,
@@ -113,7 +133,34 @@ struct response_pimpl {
113133
if (!body_future_.valid()) {
114134
body ="";
115135
}else {
116-
body = body_future_.get();
136+
std::string partial_parsed = body_future_.get();
137+
bool chunked =false;
138+
auto check = [&](std::stringconst& key, std::stringconst& value) {
139+
chunked = chunked ||boost::iequals(value,"chunked");
140+
};
141+
get_headers(std::string("Transfer-Encoding"), check);
142+
if (chunked) {
143+
auto begin = partial_parsed.begin();
144+
std::string crlf ="\r\n";
145+
for (auto iter =std::search(begin,partial_parsed.end(), crlf.begin(), crlf.end());
146+
iter != partial_parsed.end();
147+
iter =std::search(begin,partial_parsed.end(), crlf.begin(), crlf.end())) {
148+
std::stringline(begin, iter);
149+
if (line.empty())break;
150+
std::stringstreamstream(line);
151+
int len;
152+
stream >> std::hex >> len;
153+
iter +=2;
154+
if (!len)break;
155+
if (len <= partial_parsed.end() - iter) {
156+
body.insert(body.end(), iter, iter + len);
157+
iter += len;
158+
}
159+
begin = iter;
160+
}
161+
}else {
162+
std::swap(body, partial_parsed);
163+
}
117164
}
118165
}
119166

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp