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

Function handleFetchEvents

plugins/header_rewrite/operators.cc:40–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38const int LOCAL_PORT = 8080;
39
40int
41handleFetchEvents(TSCont cont, TSEvent event, void *edata)
42{
43 TSHttpTxn http_txn = static_cast<TSHttpTxn>(TSContDataGet(cont));
44
45 switch (static_cast<int>(event)) {
46 case OperatorSetBodyFrom::TS_EVENT_FETCHSM_SUCCESS: {
47 TSHttpTxn fetchsm_txn = static_cast<TSHttpTxn>(edata);
48 int data_len;
49 const char *data_start = TSFetchRespGet(fetchsm_txn, &data_len);
50 if (data_start && (data_len > 0)) {
51 const char *data_end = data_start + data_len;
52 TSHttpParser parser = TSHttpParserCreate();
53 TSMBuffer hdr_buf = TSMBufferCreate();
54 TSMLoc hdr_loc = TSHttpHdrCreate(hdr_buf);
55
56 TSHttpHdrTypeSet(hdr_buf, hdr_loc, TS_HTTP_TYPE_RESPONSE);
57 if (TSHttpHdrParseResp(parser, hdr_buf, hdr_loc, &data_start, data_end) == TS_PARSE_DONE) {
58 TSHttpTxnErrorBodySet(http_txn, TSstrdup(data_start), (data_end - data_start), nullptr);
59 } else {
60 TSWarning("[%s] Unable to parse set-custom-body fetch response", __FUNCTION__);
61 }
62 TSHttpParserDestroy(parser);
63 TSHandleMLocRelease(hdr_buf, nullptr, hdr_loc);
64 TSMBufferDestroy(hdr_buf);
65 } else {
66 TSWarning("[%s] Successful set-custom-body fetch did not result in any content", __FUNCTION__);
67 }
68 TSHttpTxnReenable(http_txn, TS_EVENT_HTTP_ERROR);
69 } break;
70 case OperatorSetBodyFrom::TS_EVENT_FETCHSM_FAILURE: {
71 Dbg(pi_dbg_ctl, "OperatorSetBodyFrom: Error getting custom body");
72 TSHttpTxnReenable(http_txn, TS_EVENT_HTTP_CONTINUE);
73 } break;
74 case OperatorSetBodyFrom::TS_EVENT_FETCHSM_TIMEOUT: {
75 Dbg(pi_dbg_ctl, "OperatorSetBodyFrom: Timeout getting custom body");
76 TSHttpTxnReenable(http_txn, TS_EVENT_HTTP_CONTINUE);
77 } break;
78 case TS_EVENT_HTTP_TXN_CLOSE: {
79 TSContDestroy(cont);
80 TSHttpTxnReenable(http_txn, TS_EVENT_HTTP_CONTINUE);
81 } break;
82 default:
83 TSError("[%s] handleFetchEvents got unknown event: %d", PLUGIN_NAME, event);
84 break;
85 }
86 return 0;
87}
88
89TSReturnCode
90createRequestString(const std::string_view &value, char (&req_buf)[MAX_SIZE], int *req_buf_size)

Callers

nothing calls this directly

Calls 15

TSContDataGetFunction · 0.85
TSFetchRespGetFunction · 0.85
TSHttpParserCreateFunction · 0.85
TSMBufferCreateFunction · 0.85
TSHttpHdrCreateFunction · 0.85
TSHttpHdrTypeSetFunction · 0.85
TSHttpHdrParseRespFunction · 0.85
TSHttpTxnErrorBodySetFunction · 0.85
TSstrdupFunction · 0.85
TSWarningFunction · 0.85
TSHttpParserDestroyFunction · 0.85
TSHandleMLocReleaseFunction · 0.85

Tested by

no test coverage detected