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

Function main_handler

plugins/regex_revalidate/regex_revalidate.cc:673–730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673static int
674main_handler(TSCont cont, TSEvent event, void *edata)
675{
676 TSHttpTxn txn = (TSHttpTxn)edata;
677 int status;
678 invalidate_t *iptr = NULL;
679 plugin_state_t *pstate = NULL;
680
681 time_t date = 0, now = 0;
682 char *url = nullptr;
683 int url_len = 0;
684
685 switch (event) {
686 case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
687 if (TSHttpTxnCacheLookupStatusGet(txn, &status) == TS_SUCCESS) {
688 if (status == TS_CACHE_LOOKUP_HIT_FRESH) {
689 pstate = (plugin_state_t *)TSContDataGet(cont);
690 iptr = pstate->invalidate_list;
691 while (iptr) {
692 if (!date) {
693 date = get_date_from_cached_hdr(txn);
694 Dbg(dbg_ctl, "Cached Date header is: %jd", intmax_t(date));
695 now = time(nullptr);
696 }
697 if (date <= iptr->epoch && now < iptr->expiry) {
698 if (!url) {
699 url = TSHttpTxnEffectiveUrlStringGet(txn, &url_len);
700 Dbg(dbg_ctl, "Effective url is is '%.*s'", url_len, url);
701 }
702 if (pcre_exec(iptr->regex, iptr->regex_extra, url, url_len, 0, 0, nullptr, 0) >= 0) {
703 Dbg(dbg_ctl, "Forced revalidate, Match with rule regex: '%s' epoch: %jd, expiry: %jd, result: '%s'", iptr->regex_text,
704 intmax_t(iptr->epoch), intmax_t(iptr->expiry), strForResult(iptr->new_result));
705 TSHttpTxnCacheLookupStatusSet(txn, iptr->new_result);
706 increment_stat(iptr->new_result);
707
708 if (pstate->match_header) {
709 add_header(txn, pstate->match_header, iptr);
710 }
711 iptr = nullptr;
712 }
713 }
714 if (iptr) {
715 iptr = iptr->next;
716 }
717 }
718 if (url) {
719 TSfree(url);
720 }
721 }
722 }
723 break;
724 default:
725 break;
726 }
727
728 TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
729 return 0;
730}

Callers

nothing calls this directly

Calls 11

TSContDataGetFunction · 0.85
pcre_execFunction · 0.85
strForResultFunction · 0.85
increment_statFunction · 0.85
TSfreeFunction · 0.85
TSHttpTxnReenableFunction · 0.85
get_date_from_cached_hdrFunction · 0.70
add_headerFunction · 0.70

Tested by

no test coverage detected