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 #712#713

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
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
remove extra body buffer copy
  • Loading branch information
@chenzhaoyu
chenzhaoyu committedDec 1, 2016
commitb950ea54019f18844047f20ab0234d85ab6b6807
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -363,25 +363,14 @@ struct http_async_connection
// Here we handle the body data ourself and append to an
// ever-growing string buffer.
auto self = this->shared_from_this();
typename protocol_base::buffer_type::const_iterator begin =
this->part_begin;
typename protocol_base::buffer_type::const_iterator end = begin;
std::advance(end, remainder);
string_type body_string(begin, end);
if (check_parse_body_complete(body_string)) {
this->append_body(remainder);
handle_received_data(body, get_body, callback,
boost::asio::error::eof, bytes_transferred);
} else {
this->parse_body(
this->parse_body(
delegate_,
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}),
remainder);
}
}
return;
case body:
Expand DownExpand Up@@ -439,25 +428,17 @@ struct http_async_connection
ec, bytes_transferred);
}));
} else {
string_type body_string(this->partial_parsed);
body_string.append(this->part.begin(), bytes_transferred);
if (check_parse_body_complete (body_string)) {
this->append_body(bytes_transferred);
handle_received_data(body, get_body, callback,
boost::asio::error::eof, bytes_transferred);
} else {
// Here we don't have a body callback. Let's make sure that we
// deal with the remainder from the headers part in case we do
// have data that's still in the buffer.
this->parse_body(
// Here we don't have a body callback. Let's make sure that we
// deal with the remainder from the headers part in case we do
// have data that's still in the buffer.
this->parse_body(
delegate_,
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);
}
}
}
return;
Expand DownExpand Up@@ -495,50 +476,6 @@ struct http_async_connection
}
}

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

inline bool parse_content_length_complete(string_type& body_string, size_t content_length){
return body_string.length() >= content_length;
}

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

typename string_type::iterator begin = body_string.begin();
for (typename string_type::iterator iter =
std::search(begin, body_string.end(), crlf.begin(), crlf.end());
iter != body_string.end();
iter =
std::search(begin, body_string.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 <= body_string.end() - iter) {
std::advance(iter, len + 2);
}
begin = iter;
}
return false;
}

string_type parse_chunk_encoding(string_type& body_string) {
string_type body;
string_type crlf = "\r\n";
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -333,9 +333,47 @@ struct http_async_protocol_handler {
parsed_ok,std::distance(std::end(result_range), part_end));
}

voidappend_body(size_t bytes) {
partial_parsed.append(part_begin, part_begin + bytes);
part_begin = part.begin();
inlineboolcheck_parse_body_complete()const {
if (this->is_chunk_encoding) {
returnparse_chunk_encoding_complete();
}
if (this->is_content_length &&this->content_length >=0) {
returnparse_content_length_complete();
}
returnfalse;
}

inlineboolparse_content_length_complete()const {
returnthis->partial_parsed.length() >=this-> content_length;
}

boolparse_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_typeline(begin, iter);
if (line.empty()) {
std::advance(iter,2);
begin = iter;
continue;
}
std::stringstreamstream(line);
int len;
stream >> std::hex >> len;
std::advance(iter,2);
if (!len)returntrue;
if (len <= partial_parsed.end() - iter) {
std::advance(iter, len +2);
}
begin = iter;
}
returnfalse;
}

template<classDelegate,classCallback>
Expand All@@ -344,8 +382,12 @@ struct http_async_protocol_handler {
// buffer.
partial_parsed.append(part_begin, part_begin + bytes);
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 Down

[8]ページ先頭

©2009-2025 Movatter.jp