@@ -47,11 +47,14 @@ using parent_select_mode_t = enum parent_select_mode {
4747 PS_CACHEKEY_URL, // Set parent selection url to cache_key url
4848};
4949
50+ constexpr std::string_view DefaultImsHeader = {" X-Crr-Ims" };
51+
5052struct pluginconfig {
5153 parent_select_mode_t ps_mode{PS_DEFAULT};
5254 bool consider_ims_header{false };
5355 bool modify_cache_key{true };
5456 bool verify_cacheability{false };
57+ std::string ims_header;
5558};
5659
5760struct txndata {
@@ -61,9 +64,6 @@ struct txndata {
6164 bool verify_cacheability{false };
6265};
6366
64- // Header for optional revalidation
65- constexpr std::string_view X_IMS_HEADER = {" X-Crr-Ims" };
66-
6767// pluginconfig struct (global plugin only)
6868pluginconfig *gPluginConfig = {nullptr };
6969
@@ -99,9 +99,10 @@ create_pluginconfig(int argc, char *const argv[])
9999 }
100100
101101 static const struct option longopts[] = {
102- {const_cast <char *>(" ps-cachekey" ), no_argument, nullptr , ' p' },
103102 {const_cast <char *>(" consider-ims" ), no_argument, nullptr , ' c' },
103+ {const_cast <char *>(" ims-header" ), required_argument, nullptr , ' i' },
104104 {const_cast <char *>(" no-modify-cachekey" ), no_argument, nullptr , ' n' },
105+ {const_cast <char *>(" ps-cachekey" ), no_argument, nullptr , ' p' },
105106 {const_cast <char *>(" verify-cacheability" ), no_argument, nullptr , ' v' },
106107 {nullptr , 0 , nullptr , 0 },
107108 };
@@ -111,24 +112,29 @@ create_pluginconfig(int argc, char *const argv[])
111112 --argv;
112113
113114 for (;;) {
114- int const opt = getopt_long (argc, argv, " " , longopts, nullptr );
115+ int const opt = getopt_long (argc, argv, " i: " , longopts, nullptr );
115116 if (-1 == opt) {
116117 break ;
117118 }
118119
119120 switch (opt) {
120- case ' p' : {
121- DEBUG_LOG (" Plugin modifies parent selection key" );
122- pc->ps_mode = PS_CACHEKEY_URL;
123- } break ;
124121 case ' c' : {
125- DEBUG_LOG (" Plugin considers the '%.*s' header" , (int )X_IMS_HEADER.size (), X_IMS_HEADER.data ());
122+ DEBUG_LOG (" Plugin considers the ims header" );
123+ pc->consider_ims_header = true ;
124+ } break ;
125+ case ' i' : {
126+ DEBUG_LOG (" Plugin uses custom ims header: %s" , optarg);
127+ pc->ims_header .assign (optarg);
126128 pc->consider_ims_header = true ;
127129 } break ;
128130 case ' n' : {
129131 DEBUG_LOG (" Plugin doesn't modify cache key" );
130132 pc->modify_cache_key = false ;
131133 } break ;
134+ case ' p' : {
135+ DEBUG_LOG (" Plugin modifies parent selection key" );
136+ pc->ps_mode = PS_CACHEKEY_URL;
137+ } break ;
132138 case ' v' : {
133139 DEBUG_LOG (" Plugin verifies whether the object in the transaction is cacheable" );
134140 pc->verify_cacheability = true ;
@@ -144,6 +150,11 @@ create_pluginconfig(int argc, char *const argv[])
144150 pc->ps_mode = PS_CACHEKEY_URL;
145151 }
146152
153+ if (pc->consider_ims_header && pc->ims_header .empty ()) {
154+ pc->ims_header = DefaultImsHeader;
155+ DEBUG_LOG (" Plugin uses default ims header: %s" , pc->ims_header .c_str ());
156+ }
157+
147158 return pc;
148159}
149160
@@ -244,12 +255,12 @@ range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
244255 }
245256 }
246257
247- // optionally consider an X-CRR-IMS header
258+ // optionally consider an ims header
248259 if (pc->consider_ims_header ) {
249- TSMLoc const imsloc = TSMimeHdrFieldFind (hdr_buf, hdr_loc, X_IMS_HEADER .data (), X_IMS_HEADER .size ());
260+ TSMLoc const imsloc = TSMimeHdrFieldFind (hdr_buf, hdr_loc, pc-> ims_header .data (), pc-> ims_header .size ());
250261 if (TS_NULL_MLOC != imsloc) {
251262 time_t const itime = TSMimeHdrFieldValueDateGet (hdr_buf, hdr_loc, imsloc);
252- DEBUG_LOG (" Servicing the '%.* s' header" , ( int )X_IMS_HEADER. size (), X_IMS_HEADER. data ());
263+ DEBUG_LOG (" Servicing the '%s' header" , pc-> ims_header . c_str ());
253264 TSHandleMLocRelease (hdr_buf, hdr_loc, imsloc);
254265 if (0 < itime) {
255266 txn_state->ims_time = itime;
@@ -303,7 +314,7 @@ handle_send_origin_request(TSCont contp, TSHttpTxn txnp, txndata *const txn_stat
303314 }
304315
305316 if (TS_SUCCESS == TSHttpTxnServerReqGet (txnp, &hdr_buf, &hdr_loc) && !rv.empty ()) {
306- if (set_header (hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE, rv.data (), rv.length ())) {
317+ if (set_header (hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE, rv.data (), rv.size ())) {
307318 DEBUG_LOG (" Added range header: %s" , rv.c_str ());
308319 TSHttpTxnHookAdd (txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, contp);
309320 }
@@ -345,7 +356,7 @@ handle_client_send_response(TSHttpTxn txnp, txndata *const txn_state)
345356 TSMLoc req_loc = TS_NULL_MLOC;
346357 if (TS_SUCCESS == TSHttpTxnClientReqGet (txnp, &req_buf, &req_loc)) {
347358 DEBUG_LOG (" Adding range header: %s" , rv.c_str ());
348- if (!set_header (req_buf, req_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE, rv.data (), rv.length ())) {
359+ if (!set_header (req_buf, req_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE, rv.data (), rv.size ())) {
349360 DEBUG_LOG (" set_header() failed." );
350361 }
351362 TSHandleMLocRelease (req_buf, TS_NULL_MLOC, req_loc);
0 commit comments