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

Function handle_write_header

plugins/experimental/icap/icap_plugin.cc:530–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530static int
531handle_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
576static int
577handle_write_body(TSCont contp, TransformData *data)

Callers 1

transform_connect_eventFunction · 0.85

Calls 14

TSIOBufferCreateFunction · 0.85
TSIOBufferReaderAllocFunction · 0.85
TSVConnWriteFunction · 0.85
TSHttpTxnClientReqGetFunction · 0.85
TSHttpTxnServerRespGetFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSHttpHdrLengthGetFunction · 0.85
memsetFunction · 0.85
TSIOBufferWriteFunction · 0.85
TSHttpHdrPrintFunction · 0.85
TSIOBufferReaderAvailFunction · 0.85
transform_write_bodyFunction · 0.85

Tested by

no test coverage detected