| 1306 | -------------------------------------------------------------------------*/ |
| 1307 | |
| 1308 | ParseResult |
| 1309 | http_parser_parse_resp(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const char **start, const char *end, |
| 1310 | bool must_copy_strings, bool eof) |
| 1311 | { |
| 1312 | if (parser->m_parsing_http) { |
| 1313 | MIMEScanner *scanner = &parser->m_mime_parser.m_scanner; |
| 1314 | |
| 1315 | ParseResult err; |
| 1316 | bool line_is_real; |
| 1317 | const char *cur; |
| 1318 | const char *line_start; |
| 1319 | const char *real_end; |
| 1320 | const char *version_start; |
| 1321 | const char *version_end; |
| 1322 | const char *status_start; |
| 1323 | const char *status_end; |
| 1324 | const char *reason_start; |
| 1325 | const char *reason_end; |
| 1326 | const char *old_start; |
| 1327 | |
| 1328 | real_end = end; |
| 1329 | old_start = *start; |
| 1330 | |
| 1331 | hh->m_polarity = HTTP_TYPE_RESPONSE; |
| 1332 | |
| 1333 | // Make sure the line is not longer than 64K |
| 1334 | if (scanner->get_buffered_line_size() >= UINT16_MAX) { |
| 1335 | return PARSE_RESULT_ERROR; |
| 1336 | } |
| 1337 | |
| 1338 | swoc::TextView text{*start, real_end}; |
| 1339 | swoc::TextView parsed; |
| 1340 | err = scanner->get(text, parsed, line_is_real, eof, MIMEScanner::LINE); |
| 1341 | *start = text.data(); |
| 1342 | if (err < 0) { |
| 1343 | return err; |
| 1344 | } |
| 1345 | // Make sure the length headers are consistent |
| 1346 | if (err == PARSE_RESULT_DONE) { |
| 1347 | err = validate_hdr_content_length(heap, hh); |
| 1348 | } |
| 1349 | if ((err == PARSE_RESULT_DONE) || (err == PARSE_RESULT_CONT)) { |
| 1350 | return err; |
| 1351 | } |
| 1352 | |
| 1353 | ink_assert(parsed.size() < UINT16_MAX); |
| 1354 | line_start = cur = parsed.data(); |
| 1355 | end = parsed.data_end(); |
| 1356 | |
| 1357 | must_copy_strings = (must_copy_strings || (!line_is_real)); |
| 1358 | |
| 1359 | #if (ENABLE_PARSER_FAST_PATHS) |
| 1360 | // first try fast path |
| 1361 | if (end - cur >= 16) { |
| 1362 | int http_match = |
| 1363 | ((cur[0] ^ 'H') | (cur[1] ^ 'T') | (cur[2] ^ 'T') | (cur[3] ^ 'P') | (cur[4] ^ '/') | (cur[6] ^ '.') | (cur[8] ^ ' ')); |
| 1364 | if ((http_match != 0) || (!(isdigit(cur[5]) && isdigit(cur[7]) && isdigit(cur[9]) && isdigit(cur[10]) && isdigit(cur[11]) && |
| 1365 | (!ParseRules::is_space(cur[13]))))) { |
no test coverage detected