| 528 | } |
| 529 | |
| 530 | static int |
| 531 | handle_write_header(TSCont contp, TransformData *data) |
| 532 | { |
| 533 | data->state = State::WRITE_HEADER; |
| 534 | data->input_buf = TSIOBufferCreate(); |
| 535 | data->input_reader = TSIOBufferReaderAlloc(data->input_buf); |
| 536 | data->icap_vio = TSVConnWrite(data->icap_vc, contp, data->input_reader, INT64_MAX); |
| 537 | |
| 538 | /* Acquire client request and server response header */ |
| 539 | TSMBuffer bufp_c, bufp_s; |
| 540 | TSMLoc req_loc, resp_loc; |
| 541 | |
| 542 | if (TSHttpTxnClientReqGet(data->txn, &bufp_c, &req_loc) != TS_SUCCESS) { |
| 543 | TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | if (TSHttpTxnServerRespGet(data->txn, &bufp_s, &resp_loc) != TS_SUCCESS) { |
| 548 | TSError("[%s] Couldn't retrieve server response header", PLUGIN_NAME); |
| 549 | TSHandleMLocRelease(bufp_c, TS_NULL_MLOC, req_loc); |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | int64_t client_req_size = TSHttpHdrLengthGet(bufp_c, req_loc); |
| 554 | int64_t server_resp_size = TSHttpHdrLengthGet(bufp_s, resp_loc); |
| 555 | /* formulate the ICAP request header */ |
| 556 | char res_buf[1000]; |
| 557 | memset(res_buf, 0, 1000); |
| 558 | snprintf(res_buf, sizeof(res_buf), |
| 559 | "RESPMOD %s ICAP/%s\r\n" |
| 560 | "Host: %s\r\n" |
| 561 | "Connection: close\r\n" // "Connection: close" is used since each scan creates a new connection |
| 562 | "Encapsulated: req-hdr=0, res-hdr=%" PRIu64 ", res-body=%" PRIu64 "\r\n\r\n", |
| 563 | ICAP_SERVICE_URL, ICAP_VERSION, server_ip.c_str(), client_req_size, server_resp_size + client_req_size); |
| 564 | |
| 565 | TSIOBufferWrite(data->input_buf, (const char *)res_buf, strlen(res_buf)); |
| 566 | TSHttpHdrPrint(bufp_c, req_loc, data->input_buf); |
| 567 | TSHttpHdrPrint(bufp_s, resp_loc, data->input_buf); |
| 568 | data->done_write += TSIOBufferReaderAvail(data->input_reader); |
| 569 | |
| 570 | TSHandleMLocRelease(bufp_c, TS_NULL_MLOC, req_loc); |
| 571 | TSHandleMLocRelease(bufp_s, TS_NULL_MLOC, resp_loc); |
| 572 | |
| 573 | return transform_write_body(data); |
| 574 | } |
| 575 | |
| 576 | static int |
| 577 | handle_write_body(TSCont contp, TransformData *data) |
no test coverage detected