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

Function TSRemapDoRemap

plugins/prefetch/plugin.cc:805–887  ·  view source on GitHub ↗

* @brief Organizes the background fetch by registering necessary hooks, by identifying front-end vs back-end, first vs second * pass. * * Remap is never done, continue with next in chain. * @param instance plugin instance pointer * @param txnp transaction handle * @param rri remap request info pointer * @return always TSREMAP_NO_REMAP */

Source from the content-addressed store, hash-verified

803 * @return always TSREMAP_NO_REMAP
804 */
805TSRemapStatus
806TSRemapDoRemap(void *instance, TSHttpTxn txnp, TSRemapRequestInfo *rri)
807{
808 PrefetchInstance *inst = static_cast<PrefetchInstance *>(instance);
809
810 if (nullptr != inst) {
811 PrefetchConfig &config = inst->_config;
812
813 int methodLen = 0;
814 const char *method = TSHttpHdrMethodGet(rri->requestBufp, rri->requestHdrp, &methodLen);
815 const String &header = config.getApiHeader();
816 if (nullptr != method && methodLen == TS_HTTP_LEN_GET && 0 == memcmp(TS_HTTP_METHOD_GET, method, TS_HTTP_LEN_GET)) {
817 bool front = config.isFront();
818 bool firstPass = false;
819 if (headerExist(rri->requestBufp, rri->requestHdrp, header.c_str(), header.length())) {
820 PrefetchDebug("%s: found %.*s", front ? "front-end" : "back-end", (int)header.length(), header.c_str());
821 /* On front-end: presence of header means second-pass, on back-end means first-pass. */
822 firstPass = !front;
823 } else {
824 /* On front-end: lack of header means first-pass, on back-end means second-pass. */
825 firstPass = front;
826 }
827
828 /* Make sure we handle only URLs that match the path pattern on the front-end + first-pass, cancel otherwise */
829 bool handleFetch = true;
830 if (front && firstPass && !config.isCmcdNor()) {
831 /* Front-end plug-in instance + first pass. */
832 if (config.getNextPath().empty()) {
833 /* No next path pattern specified then pass this request untouched. */
834 PrefetchDebug("next object pattern not specified, skip");
835 handleFetch = false;
836 } else {
837 /* Next path pattern specified hence try to match. */
838 String pristinePath = getPristineUrlPath(txnp);
839 if (!pristinePath.empty()) {
840 if (config.getNextPath().match(pristinePath)) {
841 /* Matched - handle the request */
842 PrefetchDebug("matched next object pattern");
843 inst->_state->incrementMetric(FETCH_MATCH_YES);
844 } else {
845 /* Next path pattern specified but did not match. */
846 PrefetchDebug("failed to match next object pattern, skip");
847 inst->_state->incrementMetric(FETCH_MATCH_NO);
848 handleFetch = false;
849 }
850 } else {
851 PrefetchDebug("failed to get path to (pre)match");
852 }
853
854 String queryKey = config.getQueryKeyName();
855 if (!queryKey.empty()) {
856 PrefetchDebug("handling for query-key: %s", queryKey.c_str());
857 handleFetch = true;
858 }
859 }
860 }
861
862 if (handleFetch) {

Callers

nothing calls this directly

Calls 15

TSHttpHdrMethodGetFunction · 0.85
getPristineUrlPathFunction · 0.85
TSContCreateFunction · 0.85
TSMutexCreateFunction · 0.85
TSContDataSetFunction · 0.85
TSHttpTxnHookAddFunction · 0.85
isFrontMethod · 0.80
isCmcdNorMethod · 0.80
headerExistFunction · 0.70
memcmpFunction · 0.50
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected