Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions proxy/hdrs/HTTP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,8 @@ http_parser_parse_req(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const
return PARSE_RESULT_ERROR;
}

ParseResult ret =
mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof, max_hdr_field_size);
ParseResult ret = mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof,
false, max_hdr_field_size);
// If we're done with the main parse do some validation
if (ret == PARSE_RESULT_DONE) {
ret = validate_hdr_host(hh); // check HOST header
Expand Down Expand Up @@ -1116,8 +1116,8 @@ http_parser_parse_req(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const
parser->m_parsing_http = false;
}

ParseResult ret =
mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof, max_hdr_field_size);
ParseResult ret = mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof, false,
max_hdr_field_size);
// If we're done with the main parse do some validation
if (ret == PARSE_RESULT_DONE) {
ret = validate_hdr_host(hh); // check HOST header
Expand Down Expand Up @@ -1287,7 +1287,7 @@ http_parser_parse_resp(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const

end = real_end;
parser->m_parsing_http = false;
return mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof);
return mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof, true);
}
#endif

Expand Down Expand Up @@ -1403,7 +1403,7 @@ http_parser_parse_resp(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const
parser->m_parsing_http = false;
}

return mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof);
return mime_parser_parse(&parser->m_mime_parser, heap, hh->m_fields_impl, start, end, must_copy_strings, eof, true);
}

/*-------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions proxy/hdrs/MIME.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ mime_parser_clear(MIMEParser *parser)

ParseResult
mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char **real_s, const char *real_e,
bool must_copy_strings, bool eof, size_t max_hdr_field_size)
bool must_copy_strings, bool eof, bool remove_ws_from_field_name, size_t max_hdr_field_size)
{
ParseResult err;
bool line_is_real;
Expand Down Expand Up @@ -2570,8 +2570,13 @@ mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char
// server MUST reject any received request message that contains
// whitespace between a header field-name and colon with a response code
// of 400 (Bad Request).
// A proxy MUST remove any such whitespace from a response message before
// fowarding the message downstream.
if (is_ws(field_name.back())) {
return PARSE_RESULT_ERROR;
if (!remove_ws_from_field_name) {
return PARSE_RESULT_ERROR;
}
field_name.rtrim_if(&ParseRules::is_ws);
}

// find value first
Expand Down
9 changes: 5 additions & 4 deletions proxy/hdrs/MIME.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ void mime_field_value_append(HdrHeap *heap, MIMEHdrImpl *mh, MIMEField *field, c
void mime_parser_init(MIMEParser *parser);
void mime_parser_clear(MIMEParser *parser);
ParseResult mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char **real_s, const char *real_e,
bool must_copy_strings, bool eof, size_t max_hdr_field_size = 131070);
bool must_copy_strings, bool eof, bool remove_ws_from_field_name, size_t max_hdr_field_size = 131070);

void mime_hdr_describe(HdrHeapObjImpl *raw, bool recurse);
void mime_field_block_describe(HdrHeapObjImpl *raw, bool recurse);
Expand Down Expand Up @@ -1017,7 +1017,7 @@ class MIMEHdr : public HdrHeapSDKHandle

int print(char *buf, int bufsize, int *bufindex, int *chars_to_skip);

int parse(MIMEParser *parser, const char **start, const char *end, bool must_copy_strs, bool eof,
int parse(MIMEParser *parser, const char **start, const char *end, bool must_copy_strs, bool eof, bool remove_ws_from_field_name,
size_t max_hdr_field_size = UINT16_MAX);

int value_get_index(const char *name, int name_length, const char *value, int value_length) const;
Expand Down Expand Up @@ -1299,15 +1299,16 @@ MIMEHdr::print(char *buf, int bufsize, int *bufindex, int *chars_to_skip)
-------------------------------------------------------------------------*/

inline int
MIMEHdr::parse(MIMEParser *parser, const char **start, const char *end, bool must_copy_strs, bool eof, size_t max_hdr_field_size)
MIMEHdr::parse(MIMEParser *parser, const char **start, const char *end, bool must_copy_strs, bool eof,
bool remove_ws_from_field_name, size_t max_hdr_field_size)
{
if (!m_heap)
m_heap = new_HdrHeap();

if (!m_mime)
m_mime = mime_hdr_create(m_heap);

return mime_parser_parse(parser, m_heap, m_mime, start, end, must_copy_strs, eof, max_hdr_field_size);
return mime_parser_parse(parser, m_heap, m_mime, start, end, must_copy_strs, eof, remove_ws_from_field_name, max_hdr_field_size);
}

/*-------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions proxy/hdrs/unit_tests/test_HdrUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_CASE("HdrUtils", "[proxy][hdrutils]")
mime.create(heap);
mime_parser_init(&parser);

auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true);
auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true, false);
REQUIRE(PARSE_RESULT_DONE == result);

HdrCsvIter iter;
Expand Down Expand Up @@ -144,7 +144,7 @@ TEST_CASE("HdrUtils 2", "[proxy][hdrutils]")

mime.create(heap);
mime_parser_init(&parser);
auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true);
auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true, false);
REQUIRE(PARSE_RESULT_DONE == result);

MIMEField *field{mime.field_find(connection_tag.data(), int(connection_tag.size()))};
Expand Down Expand Up @@ -187,7 +187,7 @@ TEST_CASE("HdrUtils 3", "[proxy][hdrutils]")

mime.create(heap);
mime_parser_init(&parser);
auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true);
auto result = mime_parser_parse(&parser, heap, mime.m_mime, &real_s, real_e, false, true, false);
REQUIRE(PARSE_RESULT_DONE == result);

MIMEField *field{mime.field_find(connection_tag.data(), int(connection_tag.size()))};
Expand Down
2 changes: 1 addition & 1 deletion proxy/hdrs/unit_tests/test_Hdrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")
bool must_copy_strs = false;

hdr.create(nullptr);
err = hdr.parse(&parser, &start, end, must_copy_strs, false);
err = hdr.parse(&parser, &start, end, must_copy_strs, false, false);

REQUIRE(err >= 0);

Expand Down
3 changes: 2 additions & 1 deletion src/traffic_server/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,8 @@ TSMimeHdrParse(TSMimeParser parser, TSMBuffer bufp, TSMLoc obj, const char **sta

MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj);

return (TSParseResult)mime_parser_parse((MIMEParser *)parser, ((HdrHeapSDKHandle *)bufp)->m_heap, mh, start, end, false, false);
return (TSParseResult)mime_parser_parse((MIMEParser *)parser, ((HdrHeapSDKHandle *)bufp)->m_heap, mh, start, end, false, false,
false);
}

int
Expand Down