Skip to content

Commit

Permalink
lib-http: request parser: Added support for explicitly finishing payl…
Browse files Browse the repository at this point in the history
…oad of previous request.
  • Loading branch information
stephanbosch authored and sirainen committed Feb 11, 2016
1 parent e8434aa commit d7b94e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/lib-http/http-request-parser.c
Expand Up @@ -333,7 +333,8 @@ http_request_parser_message_error(struct http_request_parser *parser)
return HTTP_REQUEST_PARSE_ERROR_BROKEN_REQUEST;
}

bool http_request_parser_pending_payload(struct http_request_parser *parser)
bool http_request_parser_pending_payload(
struct http_request_parser *parser)
{
if (parser->parser.payload == NULL)
return FALSE;
Expand Down Expand Up @@ -480,12 +481,11 @@ http_request_parse_headers(struct http_request_parser *parser,
return 0;
}

int http_request_parse_next(struct http_request_parser *parser,
pool_t pool, struct http_request *request,
enum http_request_parse_error *error_code_r, const char **error_r)
int http_request_parse_finish_payload(
struct http_request_parser *parser,
enum http_request_parse_error *error_code_r,
const char **error_r)
{
const struct http_header_field *hdr;
const char *error;
int ret;

*error_code_r = parser->error_code = HTTP_REQUEST_PARSE_ERROR_NONE;
Expand All @@ -498,8 +498,22 @@ int http_request_parse_next(struct http_request_parser *parser,
*error_code_r = http_request_parser_message_error(parser);
*error_r = parser->parser.error;
}
return ret;
}
return ret;
}

int http_request_parse_next(struct http_request_parser *parser,
pool_t pool, struct http_request *request,
enum http_request_parse_error *error_code_r, const char **error_r)
{
const struct http_header_field *hdr;
const char *error;
int ret;

/* initialize and get rid of any payload of previous request */
if ((ret=http_request_parse_finish_payload
(parser, error_code_r, error_r)) <= 0)
return ret;

/* RFC 7230, Section 3:
Expand Down
5 changes: 5 additions & 0 deletions src/lib-http/http-request-parser.h
Expand Up @@ -22,6 +22,11 @@ http_request_parser_init(struct istream *input,
const struct http_request_limits *limits) ATTR_NULL(2);
void http_request_parser_deinit(struct http_request_parser **_parser);

int http_request_parse_finish_payload(
struct http_request_parser *parser,
enum http_request_parse_error *error_code_r,
const char **error_r);

int http_request_parse_next(struct http_request_parser *parser,
pool_t pool, struct http_request *request,
enum http_request_parse_error *error_code_r, const char **error_r);
Expand Down

0 comments on commit d7b94e1

Please sign in to comment.