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

add client size close for 0.13-release#719

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -246,6 +246,10 @@ struct http_async_protocol_handler {
response_parser_type::http_header_line_done);
typename headers_container<Tag>::type headers;
std::pair<string_type, string_type> header_pair;
//init params
is_content_length = false;
content_length = -1;
is_chunk_end = false;
while (!boost::empty(input_range)) {
std::tie(parsed_ok, result_range) = headers_parser.parse_until(
response_parser_type::http_header_colon, input_range);
Expand All@@ -266,6 +270,16 @@ struct http_async_protocol_handler {
}
trim(header_pair.second);
headers.insert(header_pair);
if (!is_content_length &&
boost::iequals(header_pair.first, "Content-Length")) {
try {
content_length = std::stoll(header_pair.second);
is_content_length = true;
}
catch (std::exception&) {
//is_content_length = false;
}
}
}
// determine if the body parser will need to handle chunked encoding
typename headers_range<basic_response<Tag> >::type transfer_encoding_range =
Expand DownExpand Up@@ -325,6 +339,49 @@ struct http_async_protocol_handler {
parsed_ok, std::distance(std::end(result_range), part_end));
}

inline bool check_parse_body_complete() const {
if (this->is_chunk_encoding) {
return parse_chunk_encoding_complete();
}
if (this->is_content_length && this->content_length >= 0) {
return parse_content_length_complete();
}
return false;
}

inline bool parse_content_length_complete() const {
return this->partial_parsed.length() >= this-> content_length;
}

bool parse_chunk_encoding_complete() const {
string_type body;
string_type crlf = "\r\n";

typename string_type::const_iterator begin = partial_parsed.begin();
for (typename string_type::const_iterator iter =
std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end());
iter != partial_parsed.end();
iter =
std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end())) {
string_type line(begin, iter);
if (line.empty()) {
std::advance(iter, 2);
begin = iter;
continue;
}
std::stringstream stream(line);
int len;
stream >> std::hex >> len;
std::advance(iter, 2);
if (!len) return true;
if (len <= partial_parsed.end() - iter) {
std::advance(iter, len + 2);
}
begin = iter;
}
return false;
}

template <class Delegate, class Callback>
void parse_body(Delegate& delegate_, Callback callback, size_t bytes) {
// TODO(dberris): we should really not use a string for the partial body
Expand All@@ -333,8 +390,12 @@ struct http_async_protocol_handler {
std::advance(it, bytes);
partial_parsed.append(part_begin, it);
part_begin = part.begin();
delegate_->read_some(
boost::asio::mutable_buffers_1(part.data(), part.size()), callback);
if (check_parse_body_complete()) {
callback(boost::asio::error::eof, bytes);
} else {
delegate_->read_some(
boost::asio::mutable_buffers_1(part.data(), part.size()), callback);
}
}

typedef response_parser<Tag> response_parser_type;
Expand All@@ -353,6 +414,9 @@ struct http_async_protocol_handler {
typename buffer_type::const_iterator part_begin;
string_type partial_parsed;
bool is_chunk_encoding;
bool is_chunk_end;
bool is_content_length;
long long content_length;
};

} // namespace impl
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp