From: Timo Sirainen Date: Thu, 11 Jul 2013 06:25:53 +0000 (+0300) Subject: lib-http: Fixed handling responses whose header arrives in smaller pieces. X-Git-Tag: 2.2.5~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e904d473a024c4379a06edd36c5da187dc58ddc6;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Fixed handling responses whose header arrives in smaller pieces. --- diff --git a/src/lib-http/http-response-parser.c b/src/lib-http/http-response-parser.c index 35651cf383..7e9c469ef2 100644 --- a/src/lib-http/http-response-parser.c +++ b/src/lib-http/http-response-parser.c @@ -376,14 +376,13 @@ int http_response_parse_next(struct http_response_parser *parser, *error_r = parser->error; return ret; } + /* *( header-field CRLF ) CRLF */ + if (parser->header_parser == NULL) + parser->header_parser = http_header_parser_init(parser->input); + else + http_header_parser_reset(parser->header_parser); } - /* *( header-field CRLF ) CRLF */ - if (parser->header_parser == NULL) - parser->header_parser = http_header_parser_init(parser->input); - else - http_header_parser_reset(parser->header_parser); - while ((ret=http_header_parse_next_field (parser->header_parser, &field_name, &field_data, &field_size, &error)) > 0) { if (field_name == NULL) break; diff --git a/src/lib-http/test-http-response-parser.c b/src/lib-http/test-http-response-parser.c index 95cfaeb556..365a46d2ec 100644 --- a/src/lib-http/test-http-response-parser.c +++ b/src/lib-http/test-http-response-parser.c @@ -99,19 +99,26 @@ static void test_http_response_parse_valid(void) struct ostream *output; const struct http_response_parse_test *test; struct http_response_parser *parser; - struct http_response *response; + struct http_response *response = NULL; const char *response_text, *payload, *error; - int ret; + unsigned int response_text_len; + int ret = 0; test = &valid_response_parse_tests[i]; response_text = test->response; - input = i_stream_create_from_data(response_text, strlen(response_text)); + response_text_len = strlen(response_text); + input = test_istream_create_data(response_text, response_text_len); parser = http_response_parser_init(input); test_begin(t_strdup_printf("http response valid [%d]", i)); payload = NULL; - while ((ret=http_response_parse_next(parser, FALSE, &response, &error)) > 0) { + for (i = 0; i < response_text_len && ret == 0; i++) { + test_istream_set_size(input, i); + ret = http_response_parse_next(parser, FALSE, &response, &error); + } + test_istream_set_size(input, response_text_len); + while (ret > 0) { if (response->payload != NULL) { buffer_set_used_size(payload_buffer, 0); output = o_stream_create_buffer(payload_buffer); @@ -122,6 +129,7 @@ static void test_http_response_parse_valid(void) } else { payload = NULL; } + ret = http_response_parse_next(parser, FALSE, &response, &error); } test_out("parse success", ret == 0);