MCPcopy Create free account
hub / github.com/apache/trafficserver / mime_parser_parse

Function mime_parser_parse

src/proxy/hdrs/MIME.cc:2532–2659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2530}
2531
2532ParseResult
2533mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char **real_s, const char *real_e,
2534 bool must_copy_strings, bool eof, bool remove_ws_from_field_name, size_t max_hdr_field_size)
2535{
2536 ParseResult err;
2537 bool line_is_real;
2538
2539 MIMEScanner *scanner = &parser->m_scanner;
2540
2541 while (true) {
2542 ////////////////////////////////////////////////////////////////////////////
2543 // get a name:value line, with all continuation lines glued into one line //
2544 ////////////////////////////////////////////////////////////////////////////
2545
2546 TextView text{*real_s, real_e};
2547 TextView parsed;
2548 err = scanner->get(text, parsed, line_is_real, eof, MIMEScanner::FIELD);
2549 *real_s = text.data();
2550 if (err != PARSE_RESULT_OK) {
2551 return err;
2552 }
2553
2554 //////////////////////////////////////////////////
2555 // if got a LF or CR on its own, end the header //
2556 //////////////////////////////////////////////////
2557
2558 if ((parsed.size() >= 2) && (parsed[0] == ParseRules::CHAR_CR) && (parsed[1] == ParseRules::CHAR_LF)) {
2559 return PARSE_RESULT_DONE;
2560 }
2561
2562 if ((parsed.size() >= 1) && (parsed[0] == ParseRules::CHAR_LF)) {
2563 return PARSE_RESULT_DONE;
2564 }
2565
2566 /////////////////////////////////////////////
2567 // find pointers into the name:value field //
2568 /////////////////////////////////////////////
2569
2570 /**
2571 * Fix for INKqa09141. The is_token function fails for '@' character.
2572 * Header names starting with '@' signs are valid headers. Hence we
2573 * have to add one more check to see if the first parameter is '@'
2574 * character then, the header name is valid.
2575 **/
2576 if ((!ParseRules::is_token(*parsed)) && (*parsed != '@')) {
2577 continue; // toss away garbage line
2578 }
2579
2580 // find name last
2581 auto field_value = parsed; // need parsed as is later on.
2582 auto field_name = field_value.split_prefix_at(':');
2583 if (field_name.empty()) {
2584 continue; // toss away garbage line
2585 }
2586
2587 // RFC7230 section 3.2.4:
2588 // No whitespace is allowed between the header field-name and colon. In
2589 // the past, differences in the handling of such whitespace have led to

Callers 5

http_parser_parse_reqFunction · 0.85
http_parser_parse_respFunction · 0.85
test_HdrUtils.ccFile · 0.85
TSMimeHdrParseFunction · 0.85
parseMethod · 0.85

Calls 13

is_wsFunction · 0.85
hdrtoken_tokenizeFunction · 0.85
mime_field_createFunction · 0.85
mime_hdr_field_attachFunction · 0.85
split_prefix_atMethod · 0.80
duplicate_strMethod · 0.80
getMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
suffixMethod · 0.45

Tested by

no test coverage detected