Skip to content

Commit

Permalink
lib-http: message parser: Delay allocation of message header.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and GitLab committed Feb 15, 2017
1 parent 8b223f0 commit b04dfad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib-http/http-message-parser.c
Expand Up @@ -61,7 +61,6 @@ void http_message_parser_restart(struct http_message_parser *parser,
pool_ref(pool);
}
parser->msg.date = (time_t)-1;
parser->msg.header = http_header_create(parser->msg.pool, 32);
}

int http_message_parse_version(struct http_message_parser *parser)
Expand Down Expand Up @@ -132,6 +131,8 @@ http_message_parse_header(struct http_message_parser *parser,
const struct http_header_field *hdr;
struct http_parser hparser;

if (parser->msg.header == NULL)
parser->msg.header = http_header_create(parser->msg.pool, 32);
hdr = http_header_field_add(parser->msg.header, name, data, size);

/* RFC 7230, Section 3.2.2: Field Order
Expand Down Expand Up @@ -356,6 +357,10 @@ int http_message_parse_headers(struct http_message_parser *parser)
if (field_name == NULL) {
/* EOH */

/* Create empty header if there is none */
if (parser->msg.header == NULL)
parser->msg.header = http_header_create(parser->msg.pool, 1);

/* handle HTTP/1.0 persistence */
if (msg->version_major == 1 && msg->version_minor == 0 &&
!msg->connection_close) {
Expand Down

0 comments on commit b04dfad

Please sign in to comment.