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

Function handleReadRequestHeader

plugins/esi/combo_handler.cc:463–516  ·  view source on GitHub ↗

Handle TS_EVENT_HTTP_OS_DNS event after TS_EVENT_HTTP_POST_REMAP and TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE in order to make this plugin "per-remap configurable", that is, we enable combo for specific channels, and disable for other channels. In yahoo's original code, this function handle TS_EVENT_HTTP_READ_REQUEST_HDR. Because TS_EVENT_HTTP_READ_REQUEST_HDR is before TSRemapDoRemap, we ca

Source from the content-addressed store, hash-verified

461 read "plugin_enable" flag in the READ_REQUEST_HDR event.
462*/
463static int
464handleReadRequestHeader(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
465{
466 TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
467
468 if (event != TS_EVENT_HTTP_OS_DNS) {
469 LOG_ERROR("unknown event for this plugin %d", event);
470 return 0;
471 }
472
473 if (1 != reinterpret_cast<intptr_t>(TSUserArgGet(txnp, arg_idx))) {
474 LOG_DEBUG("combo is disabled for this channel");
475 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
476 return 0;
477 }
478
479 LOG_DEBUG("combo is enabled for this channel");
480 LOG_DEBUG("handling TS_EVENT_HTTP_OS_DNS event");
481
482 TSEvent reenable_to_event = TS_EVENT_HTTP_CONTINUE;
483 TSMBuffer bufp;
484 TSMLoc hdr_loc;
485
486 if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) == TS_SUCCESS) {
487 TSMLoc url_loc;
488 if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) == TS_SUCCESS) {
489 if (isComboHandlerRequest(bufp, hdr_loc, url_loc)) {
490 TSCont contp = TSContCreate(handleServerEvent, TSMutexCreate());
491 if (!contp) {
492 LOG_ERROR("[%s] Could not create intercept request", __FUNCTION__);
493 reenable_to_event = TS_EVENT_HTTP_ERROR;
494 } else {
495 TSHttpTxnServerIntercept(contp, txnp);
496 InterceptData *int_data = new InterceptData(contp);
497 TSContDataSet(contp, int_data);
498 // todo: check if these two cacheable sets are required
499 TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, true);
500 TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, true);
501 getClientRequest(txnp, bufp, hdr_loc, url_loc, int_data->creq);
502 LOG_DEBUG("Setup server intercept to handle client request");
503 }
504 }
505 TSHandleMLocRelease(bufp, hdr_loc, url_loc);
506 } else {
507 LOG_ERROR("Could not get request URL");
508 }
509 TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
510 } else {
511 LOG_ERROR("Could not get client request");
512 }
513
514 TSHttpTxnReenable(txnp, reenable_to_event);
515 return 1;
516}
517
518static bool
519isComboHandlerRequest(TSMBuffer bufp, TSMLoc hdr_loc, TSMLoc url_loc)

Callers

nothing calls this directly

Calls 12

TSUserArgGetFunction · 0.85
TSHttpTxnReenableFunction · 0.85
TSHttpTxnClientReqGetFunction · 0.85
TSHttpHdrUrlGetFunction · 0.85
isComboHandlerRequestFunction · 0.85
TSContCreateFunction · 0.85
TSMutexCreateFunction · 0.85
TSHttpTxnServerInterceptFunction · 0.85
TSContDataSetFunction · 0.85
TSHttpTxnCntlSetFunction · 0.85
getClientRequestFunction · 0.85
TSHandleMLocReleaseFunction · 0.85

Tested by

no test coverage detected