Skip to content

Commit

Permalink
body.reserve(content_lenght)
Browse files Browse the repository at this point in the history
  • Loading branch information
hewei.it committed Nov 4, 2020
1 parent caedc27 commit afcc318
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions http/Http1Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ int on_headers_complete(http_parser* parser) {
if (iter != hp->parsed->headers.end()) {
hp->parsed->content_type = http_content_type_enum(iter->second.c_str());
}
iter = hp->parsed->headers.find("content-length");
if (iter != hp->parsed->headers.end()) {
int content_length = atoi(iter->second.c_str());
hp->parsed->content_length = content_length;
if (content_length > hp->parsed->body.capacity()) {
hp->parsed->body.reserve(content_length);
}
}
hp->parsed->http_major = parser->http_major;
hp->parsed->http_minor = parser->http_minor;
if (hp->parsed->type == HTTP_REQUEST) {
Expand Down

0 comments on commit afcc318

Please sign in to comment.