| 399 | } |
| 400 | |
| 401 | void |
| 402 | FetchSM::get_info_from_buffer(IOBufferReader *reader) |
| 403 | { |
| 404 | char *buf, *info; |
| 405 | IOBufferBlock *blk; |
| 406 | int64_t read_avail, read_done; |
| 407 | |
| 408 | if (!reader) { |
| 409 | client_bytes = 0; |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | /* Read the data out of the reader */ |
| 414 | if (reader->block != NULL) |
| 415 | reader->skip_empty_blocks(); |
| 416 | |
| 417 | read_avail = reader->read_avail(); |
| 418 | Dbg(dbg_ctl, "[%s] total avail %" PRId64, __FUNCTION__, read_avail); |
| 419 | if (!read_avail) { |
| 420 | client_bytes = 0; |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | info = (char *)ats_malloc(sizeof(char) * (read_avail + 1)); |
| 425 | client_response = info; |
| 426 | |
| 427 | blk = reader->block.get(); |
| 428 | |
| 429 | // This is the equivalent of TSIOBufferBlockReadStart() |
| 430 | buf = blk->start() + reader->start_offset; |
| 431 | read_done = blk->read_avail() - reader->start_offset; |
| 432 | |
| 433 | if (header_done == 0 && read_done > 0) { |
| 434 | int bytes_used = 0; |
| 435 | header_done = true; |
| 436 | if (client_response_hdr.parse_resp(&http_parser, reader, &bytes_used, 0) == PARSE_RESULT_DONE) { |
| 437 | if ((bytes_used > 0) && (bytes_used <= read_avail)) { |
| 438 | memcpy(info, buf, bytes_used); |
| 439 | info += bytes_used; |
| 440 | client_bytes += bytes_used; |
| 441 | } |
| 442 | } else { |
| 443 | Error("Failed to parse headers in FetchSM buffer"); |
| 444 | } |
| 445 | // adjust the read_avail |
| 446 | read_avail -= bytes_used; |
| 447 | } |
| 448 | |
| 449 | // Send the body without dechunk when neither streaming nor dechunk flag is set |
| 450 | // Or when the body is not chunked |
| 451 | if (!((fetch_flags & TS_FETCH_FLAGS_STREAM) || (fetch_flags & TS_FETCH_FLAGS_DECHUNK)) || !check_chunked()) { |
| 452 | /* Read the data out of the reader */ |
| 453 | while (read_avail > 0) { |
| 454 | if (reader->block) { |
| 455 | reader->skip_empty_blocks(); |
| 456 | } |
| 457 | |
| 458 | blk = reader->block.get(); |
nothing calls this directly
no test coverage detected