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
| 461 | read "plugin_enable" flag in the READ_REQUEST_HDR event. |
| 462 | */ |
| 463 | static int |
| 464 | handleReadRequestHeader(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 | |
| 518 | static bool |
| 519 | isComboHandlerRequest(TSMBuffer bufp, TSMLoc hdr_loc, TSMLoc url_loc) |
nothing calls this directly
no test coverage detected