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

Function transform_plugin

plugins/compress/compress.cc:1007–1078  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1005}
1006
1007static int
1008transform_plugin(TSCont contp, TSEvent event, void *edata)
1009{
1010 TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
1011 int compress_type = COMPRESSION_TYPE_DEFAULT;
1012 int algorithms = ALGORITHM_DEFAULT;
1013 HostConfiguration *hc = static_cast<HostConfiguration *>(TSContDataGet(contp));
1014
1015 switch (event) {
1016 case TS_EVENT_HTTP_READ_RESPONSE_HDR:
1017 // os: the accept encoding header needs to be restored..
1018 // otherwise the next request won't get a cache hit on this
1019 if (hc != nullptr) {
1020 info("reading response headers");
1021 if (hc->remove_accept_encoding()) {
1022 TSMBuffer req_buf;
1023 TSMLoc req_loc;
1024
1025 if (TSHttpTxnServerReqGet(txnp, &req_buf, &req_loc) == TS_SUCCESS) {
1026 restore_accept_encoding(txnp, req_buf, req_loc, global_hidden_header_name);
1027 TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc);
1028 }
1029 }
1030
1031 handle_compression_and_vary(txnp, true, hc, &compress_type, &algorithms);
1032 }
1033 break;
1034
1035 case TS_EVENT_HTTP_SEND_REQUEST_HDR:
1036 if (hc != nullptr) {
1037 info("preparing send request headers");
1038 if (hc->remove_accept_encoding()) {
1039 TSMBuffer req_buf;
1040 TSMLoc req_loc;
1041
1042 if (TSHttpTxnServerReqGet(txnp, &req_buf, &req_loc) == TS_SUCCESS) {
1043 hide_accept_encoding(txnp, req_buf, req_loc, global_hidden_header_name);
1044 TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc);
1045 }
1046 }
1047 TSHttpTxnHookAdd(txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, contp);
1048 }
1049 break;
1050
1051 case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE: {
1052 int obj_status;
1053
1054 if (TS_ERROR != TSHttpTxnCacheLookupStatusGet(txnp, &obj_status) && (TS_CACHE_LOOKUP_HIT_FRESH == obj_status)) {
1055 if (hc != nullptr) {
1056 info("handling compression of cached object");
1057 handle_compression_and_vary(txnp, false, hc, &compress_type, &algorithms);
1058 }
1059 } else {
1060 // Prepare for going to origin
1061 info("preparing to go to origin");
1062 TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, contp);
1063 }
1064 } break;

Callers

nothing calls this directly

Calls 11

TSContDataGetFunction · 0.85
TSHttpTxnServerReqGetFunction · 0.85
restore_accept_encodingFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
hide_accept_encodingFunction · 0.85
TSHttpTxnHookAddFunction · 0.85
TSContDestroyFunction · 0.85
TSHttpTxnReenableFunction · 0.85

Tested by

no test coverage detected