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

Function local_handler

tests/tools/plugins/custom204plugin.cc:34–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34static int
35local_handler(TSCont contp, TSEvent event, void *edata)
36{
37 const char *msg = "<HTML>\n"
38 "<HEAD>\n"
39 "<TITLE>Spec-breaking 204!</TITLE>\n"
40 "</HEAD>\n"
41 "\n"
42 "<BODY>\n"
43 "<H1>This is body content for a 204.</H1>\n"
44 "<HR>\n"
45 "\n"
46 "Description: According to rfc7231 I should not have been sent to you!<BR/>\n"
47 "This response was sent via the custom204plugin via a call to TSHttpTxnErrorBodySet.\n"
48 "<HR>\n"
49 "</BODY>";
50 TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
51 TSMBuffer bufp = nullptr;
52 TSMLoc hdr_loc = nullptr;
53 TSMLoc url_loc = nullptr;
54 ;
55 const char *host = nullptr;
56 int host_length;
57 const char *test_host = "www.customplugin204.test";
58
59 switch (event) {
60 case TS_EVENT_HTTP_PRE_REMAP:
61 Dbg(dbg_ctl, "event TS_EVENT_HTTP_PRE_REMAP received");
62 Dbg(dbg_ctl, "running plugin logic.");
63 if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
64 Dbg(dbg_ctl, "Couldn't retrieve client request header");
65 TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
66 goto done;
67 }
68 Dbg(dbg_ctl, "got client request");
69
70 if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
71 TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME);
72 Dbg(dbg_ctl, "Couldn't retrieve request url");
73 TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
74 goto done;
75 }
76 Dbg(dbg_ctl, "got client request url");
77
78 host = TSUrlHostGet(bufp, url_loc, &host_length);
79 if (!host) {
80 TSError("[%s] Couldn't retrieve request hostname", PLUGIN_NAME);
81 Dbg(dbg_ctl, "Couldn't retrieve request hostname");
82 TSHandleMLocRelease(bufp, hdr_loc, url_loc);
83 TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
84 goto done;
85 }
86 Dbg(dbg_ctl, "request's host was retrieved");
87
88 if (strncmp(host, test_host, strlen(test_host)) == 0) {
89 Dbg(dbg_ctl, "host matches, hook TS_HTTP_SEND_RESPONSE_HDR_HOOK");
90 TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, contp);
91 TSHandleMLocRelease(bufp, hdr_loc, url_loc);

Callers

nothing calls this directly

Calls 11

TSHttpTxnClientReqGetFunction · 0.85
TSHttpHdrUrlGetFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSUrlHostGetFunction · 0.85
TSHttpTxnHookAddFunction · 0.85
TSHttpTxnReenableFunction · 0.85
TSHttpTxnStatusSetFunction · 0.85
TSHttpTxnErrorBodySetFunction · 0.85
TSstrdupFunction · 0.85
TSContDestroyFunction · 0.85
TSErrorFunction · 0.50

Tested by

no test coverage detected