| 511 | } |
| 512 | |
| 513 | void |
| 514 | FetchSM::process_fetch_read(int event) |
| 515 | { |
| 516 | Dbg(dbg_ctl, "[%s] I am here read", __FUNCTION__); |
| 517 | int64_t bytes; |
| 518 | int bytes_used; |
| 519 | int64_t total_bytes_copied = 0; |
| 520 | |
| 521 | switch (event) { |
| 522 | case TS_EVENT_VCONN_READ_READY: |
| 523 | // duplicate the bytes for backward compatibility with TSFetchUrl() |
| 524 | if (!(fetch_flags & TS_FETCH_FLAGS_STREAM)) { |
| 525 | bytes = resp_reader->read_avail(); |
| 526 | Dbg(dbg_ctl, "[%s] number of bytes in read ready %" PRId64, __FUNCTION__, bytes); |
| 527 | |
| 528 | while (total_bytes_copied < bytes) { |
| 529 | int64_t actual_bytes_copied; |
| 530 | actual_bytes_copied = resp_buffer->write(resp_reader, bytes, 0); |
| 531 | Dbg(dbg_ctl, "[%s] copied %" PRId64 " bytes", __FUNCTION__, actual_bytes_copied); |
| 532 | if (actual_bytes_copied <= 0) { |
| 533 | break; |
| 534 | } |
| 535 | total_bytes_copied += actual_bytes_copied; |
| 536 | } |
| 537 | Dbg(dbg_ctl, "[%s] total copied %" PRId64 " bytes", __FUNCTION__, total_bytes_copied); |
| 538 | resp_reader->consume(total_bytes_copied); |
| 539 | } |
| 540 | |
| 541 | if (header_done == 0 && ((fetch_flags & TS_FETCH_FLAGS_STREAM) || callback_options == AFTER_HEADER)) { |
| 542 | if (client_response_hdr.parse_resp(&http_parser, resp_reader, &bytes_used, false) == PARSE_RESULT_DONE) { |
| 543 | header_done = true; |
| 544 | if (fetch_flags & TS_FETCH_FLAGS_STREAM) { |
| 545 | return InvokePluginExt(); |
| 546 | } else { |
| 547 | InvokePlugin(callback_events.success_event_id, (void *)&client_response_hdr); |
| 548 | } |
| 549 | } |
| 550 | } else { |
| 551 | if (fetch_flags & TS_FETCH_FLAGS_STREAM) { |
| 552 | return InvokePluginExt(); |
| 553 | } |
| 554 | } |
| 555 | read_vio->reenable(); |
| 556 | break; |
| 557 | case TS_EVENT_VCONN_READ_COMPLETE: |
| 558 | case TS_EVENT_VCONN_EOS: |
| 559 | if (fetch_flags & TS_FETCH_FLAGS_STREAM) { |
| 560 | return InvokePluginExt(event); |
| 561 | } |
| 562 | if (callback_options == AFTER_HEADER || callback_options == AFTER_BODY) { |
| 563 | get_info_from_buffer(resp_reader); |
| 564 | InvokePlugin(callback_events.success_event_id, (void *)this); |
| 565 | } |
| 566 | Dbg(dbg_ctl, "[%s] received EOS", __FUNCTION__); |
| 567 | cleanUp(); |
| 568 | break; |
| 569 | case TS_EVENT_ERROR: |
| 570 | default: |
nothing calls this directly
no test coverage detected