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

Method get_info_from_buffer

src/proxy/FetchSM.cc:401–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401void
402FetchSM::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();

Callers

nothing calls this directly

Calls 9

ats_mallocFunction · 0.85
skip_empty_blocksMethod · 0.80
memcpyFunction · 0.50
ErrorClass · 0.50
read_availMethod · 0.45
getMethod · 0.45
startMethod · 0.45
parse_respMethod · 0.45
consumeMethod · 0.45

Tested by

no test coverage detected