You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2021/11/02 13:08:54 UTC

[GitHub] [trafficserver] traeak opened a new pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

traeak opened a new pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488


   The cache_range_requests plugin expects the parent to have the reason set to "Partial Content" (case insensiitve) in addition to the expecting a 206 status.
   
   This PR will hard set the Reason to "Partial Content" if not already set.
   
   closes #8481 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] mlibbey commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
mlibbey commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957847780


   Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations
      -- they can be replaced by local equivalents without affecting the  protocol), wouldn't it be better just to ignore the reason code entirely?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak edited a comment on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak edited a comment on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564


   > Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations -- they can be replaced by local equivalents without affecting the protocol), wouldn't it be better just to ignore the reason code entirely?
   
   That's why the PR is still in draft.  If the plugin tries to pass a legit 200 down from a server response it shouldn't retag it 206 while sending it to the client.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#discussion_r745810654



##########
File path: plugins/cache_range_requests/cache_range_requests.cc
##########
@@ -185,110 +186,105 @@ handle_read_request_header(TSCont txn_contp, TSEvent event, void *edata)
 void
 range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
 {
-  char cache_key_url[8192] = {0};
-  char *req_url;
-  int length, url_length, cache_key_url_length;
-  txndata *txn_state;
-  TSMBuffer hdr_buf;
-  TSMLoc hdr_loc = nullptr;
-  TSMLoc loc     = nullptr;
-  TSCont txn_contp;
+  txndata *txn_state = nullptr;
+
+  TSMBuffer hdr_buf = nullptr;
+  TSMLoc hdr_loc    = TS_NULL_MLOC;
 
   if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &hdr_buf, &hdr_loc)) {
-    loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
-    if (TS_NULL_MLOC != loc) {
-      const char *hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf, hdr_loc, loc, 0, &length);
-      TSHandleMLocRelease(hdr_buf, hdr_loc, loc);
+    TSMLoc const range_loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
+    if (TS_NULL_MLOC != range_loc) {
+      int len                     = 0;
+      char const *const hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf, hdr_loc, range_loc, 0, &len);
 
-      if (!hdr_value || length <= 0) {
+      if (!hdr_value || len <= 0) {
         DEBUG_LOG("Not a range request.");
       } else {
-        if (nullptr == (txn_contp = TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr))) {
-          ERROR_LOG("failed to create the transaction handler continuation.");
-        } else {
-          txn_state       = new txndata;
-          std::string &rv = txn_state->range_value;
-          rv.assign(hdr_value, length);
-          DEBUG_LOG("length: %d, txn_state->range_value: %s", length, rv.c_str());
-          if (nullptr != pc) {
-            if (pc->modify_cache_key || PS_DEFAULT != pc->ps_mode) {
-              req_url              = TSHttpTxnEffectiveUrlStringGet(txnp, &url_length);
-              cache_key_url_length = snprintf(cache_key_url, 8192, "%s-%s", req_url, rv.c_str());
-              DEBUG_LOG("Forming new cache URL for '%s': '%s'", req_url, cache_key_url);
-              if (req_url != nullptr) {
-                TSfree(req_url);
-              }
+        txn_state = new txndata;
+        txn_state->range_value.assign(hdr_value, len);
+
+        std::string const &rv = txn_state->range_value;
+        DEBUG_LOG("txn_state->range_value: '%s'", rv.c_str());
+
+        // Consider config options
+        if (nullptr != pc) {
+          char cache_key_url[16384] = {0};
+          int cache_key_url_len     = 0;
+
+          if (pc->modify_cache_key || PS_CACHEKEY_URL == pc->ps_mode) {
+            int url_len         = 0;
+            char *const req_url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_len);
+            cache_key_url_len   = snprintf(cache_key_url, sizeof(cache_key_url), "%s-%s", req_url, rv.c_str());
+            DEBUG_LOG("Forming new cache URL for '%s': '%.*s'", req_url, cache_key_url_len, cache_key_url);
+            if (req_url != nullptr) {
+              TSfree(req_url);
             }
+          }
 
-            // set the cache key if configured to.
-            if (pc->modify_cache_key) {
-              if (TS_SUCCESS == TSCacheUrlSet(txnp, cache_key_url, cache_key_url_length)) {
-                DEBUG_LOG("Setting cache key to '%s'", cache_key_url);
-              } else {
-                ERROR_LOG("failed to change the cache url to '%s'", cache_key_url);
-                ERROR_LOG("Disabling cache for this transaction to avoid cache poisoning.");
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
-              }
+          // Modify the cache_key
+          if (pc->modify_cache_key) {
+            DEBUG_LOG("Setting cache key to '%.*s'", cache_key_url_len, cache_key_url);
+            if (TS_SUCCESS != TSCacheUrlSet(txnp, cache_key_url, cache_key_url_len)) {
+              ERROR_LOG("Failed to change the cache url, disabling cache for this transaction to avoid cache poisoning.");
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
             }
+          }
 
-            // Optionally set the parent_selection_url to the cache_key url or path
-            if (PS_DEFAULT != pc->ps_mode) {
-              TSMLoc ps_loc = nullptr;
-
-              if (PS_CACHEKEY_URL == pc->ps_mode) {
-                const char *start = cache_key_url;
-                const char *end   = cache_key_url + cache_key_url_length;
-                if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc) &&
-                    TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end) && // This should always succeed.
-                    TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp, hdr_buf, ps_loc)) {
-                  DEBUG_LOG("Setting Parent Selection URL to '%s'", cache_key_url);
-                  TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
-                }
+          // Set the parent_selection_url to the modified cache_key.
+          if (PS_CACHEKEY_URL == pc->ps_mode) {
+            TSMLoc ps_loc     = TS_NULL_MLOC;
+            const char *start = cache_key_url;
+            const char *end   = cache_key_url + cache_key_url_len;
+            if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc)) {
+              if (TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end) && // This should always succeed.
+                  TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp, hdr_buf, ps_loc)) {
+                DEBUG_LOG("Setting Parent Selection URL to '%.*s'", cache_key_url_len, cache_key_url);
               }
+              TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
             }
+          }
 
-            // optionally consider an X-CRR-IMS header
-            if (pc->consider_ims_header) {
-              TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, X_IMS_HEADER.data(), X_IMS_HEADER.size());
-              if (TS_NULL_MLOC != imsloc) {
-                time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf, hdr_loc, imsloc);
-                DEBUG_LOG("Servicing the '%.*s' header", (int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
-                TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
-                if (0 < itime) {
-                  txn_state->ims_time = itime;
-                }
+          // optionally consider an X-CRR-IMS header
+          if (pc->consider_ims_header) {
+            TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, X_IMS_HEADER.data(), X_IMS_HEADER.size());
+            if (TS_NULL_MLOC != imsloc) {
+              time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf, hdr_loc, imsloc);
+              DEBUG_LOG("Servicing the '%.*s' header", (int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
+              TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
+              if (0 < itime) {
+                txn_state->ims_time = itime;
               }
             }
-
-            txn_state->verify_cacheability = pc->verify_cacheability;
           }
 
-          // remove the range request header.
-          if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE) > 0) {
-            DEBUG_LOG("Removed the Range: header from the request.");
-          }
+          txn_state->verify_cacheability = pc->verify_cacheability;
+        }
 
-          TSContDataSet(txn_contp, txn_state);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, txn_contp);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, txn_contp);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, txn_contp);
-          DEBUG_LOG("Added TS_HTTP_SEND_REQUEST_HDR_HOOK, TS_HTTP_SEND_RESPONSE_HDR_HOOK, and TS_HTTP_TXN_CLOSE_HOOK");
+        // remove the range request header.
+        if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE) > 0) {
+          DEBUG_LOG("Removed the Range: header from the request.");
+        }
 
-          if (0 < txn_state->ims_time) {
-            TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, txn_contp);
-            DEBUG_LOG("Also Added TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK");
-          }
+        // Set up the continuation
+        TSCont const txn_contp = TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr);

Review comment:
       The cast seems to do nothing (kruft).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-959077024






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak merged pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak merged pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak edited a comment on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak edited a comment on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564


   > Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations -- they can be replaced by local equivalents without affecting the protocol), wouldn't it be better just to ignore the reason code entirely?
   
   That's why the PR is still in draft.  If the plugin tries to pass a legit 200 down from a server response it shouldn't retag it 206 while sending it to the client... should have a solution here soon.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] mlibbey commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
mlibbey commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957847780


   Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations
      -- they can be replaced by local equivalents without affecting the  protocol), wouldn't it be better just to ignore the reason code entirely?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ezelkow1 commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
ezelkow1 commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957805258


   [approve ci]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ezelkow1 commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
ezelkow1 commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957805258


   [approve ci]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-959077024


   [approve ci autest]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564


   > Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations -- they can be replaced by local equivalents without affecting the protocol), wouldn't it be better just to ignore the reason code entirely?
   
   That's why the PR is still in draft.  If the plugin tries to send a legit 200 down from a server response it shouldn't retag it 206 while sending it to the client.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#discussion_r745884128



##########
File path: plugins/cache_range_requests/cache_range_requests.cc
##########
@@ -185,110 +186,105 @@ handle_read_request_header(TSCont txn_contp, TSEvent event, void *edata)
 void
 range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
 {
-  char cache_key_url[8192] = {0};
-  char *req_url;
-  int length, url_length, cache_key_url_length;
-  txndata *txn_state;
-  TSMBuffer hdr_buf;
-  TSMLoc hdr_loc = nullptr;
-  TSMLoc loc     = nullptr;
-  TSCont txn_contp;
+  txndata *txn_state = nullptr;

Review comment:
       You could have moved the definition of txn_state to line 203.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-959077024


   [approve ci autest]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564


   > Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations -- they can be replaced by local equivalents without affecting the protocol), wouldn't it be better just to ignore the reason code entirely?
   
   That's why the PR is still in draft.  If the plugin tries to send a legit 200 down from a server response it shouldn't retag it 206 while sending it to the client.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] mlibbey commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
mlibbey commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957847780


   Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations
      -- they can be replaced by local equivalents without affecting the  protocol), wouldn't it be better just to ignore the reason code entirely?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on a change in pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak commented on a change in pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#discussion_r745897346



##########
File path: plugins/cache_range_requests/cache_range_requests.cc
##########
@@ -185,110 +186,105 @@ handle_read_request_header(TSCont txn_contp, TSEvent event, void *edata)
 void
 range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
 {
-  char cache_key_url[8192] = {0};
-  char *req_url;
-  int length, url_length, cache_key_url_length;
-  txndata *txn_state;
-  TSMBuffer hdr_buf;
-  TSMLoc hdr_loc = nullptr;
-  TSMLoc loc     = nullptr;
-  TSCont txn_contp;
+  txndata *txn_state = nullptr;

Review comment:
       moved.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ezelkow1 commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
ezelkow1 commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957805258


   [approve ci]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak edited a comment on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak edited a comment on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak commented on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564


   > Since the reason text in the status codes are RFC recommendations (https://datatracker.ietf.org/doc/html/rfc7231#section-6.1 -- The reason phrases listed here are only recommendations -- they can be replaced by local equivalents without affecting the protocol), wouldn't it be better just to ignore the reason code entirely?
   
   That's why the PR is still in draft.  If the plugin tries to send a legit 200 down from a server response it shouldn't retag it 206 while sending it to the client.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak edited a comment on pull request #8488: cache_range_requests plugin: hard set reason string for handled 206 response

Posted by GitBox <gi...@apache.org>.
traeak edited a comment on pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#issuecomment-957903564






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] traeak commented on a change in pull request #8488: cache_range_requests plugin: don't require 206 Partial Content reason string

Posted by GitBox <gi...@apache.org>.
traeak commented on a change in pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#discussion_r745875385



##########
File path: plugins/cache_range_requests/cache_range_requests.cc
##########
@@ -185,110 +186,105 @@ handle_read_request_header(TSCont txn_contp, TSEvent event, void *edata)
 void
 range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
 {
-  char cache_key_url[8192] = {0};
-  char *req_url;
-  int length, url_length, cache_key_url_length;
-  txndata *txn_state;
-  TSMBuffer hdr_buf;
-  TSMLoc hdr_loc = nullptr;
-  TSMLoc loc     = nullptr;
-  TSCont txn_contp;
+  txndata *txn_state = nullptr;
+
+  TSMBuffer hdr_buf = nullptr;
+  TSMLoc hdr_loc    = TS_NULL_MLOC;
 
   if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &hdr_buf, &hdr_loc)) {
-    loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
-    if (TS_NULL_MLOC != loc) {
-      const char *hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf, hdr_loc, loc, 0, &length);
-      TSHandleMLocRelease(hdr_buf, hdr_loc, loc);
+    TSMLoc const range_loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
+    if (TS_NULL_MLOC != range_loc) {
+      int len                     = 0;
+      char const *const hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf, hdr_loc, range_loc, 0, &len);
 
-      if (!hdr_value || length <= 0) {
+      if (!hdr_value || len <= 0) {
         DEBUG_LOG("Not a range request.");
       } else {
-        if (nullptr == (txn_contp = TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr))) {
-          ERROR_LOG("failed to create the transaction handler continuation.");
-        } else {
-          txn_state       = new txndata;
-          std::string &rv = txn_state->range_value;
-          rv.assign(hdr_value, length);
-          DEBUG_LOG("length: %d, txn_state->range_value: %s", length, rv.c_str());
-          if (nullptr != pc) {
-            if (pc->modify_cache_key || PS_DEFAULT != pc->ps_mode) {
-              req_url              = TSHttpTxnEffectiveUrlStringGet(txnp, &url_length);
-              cache_key_url_length = snprintf(cache_key_url, 8192, "%s-%s", req_url, rv.c_str());
-              DEBUG_LOG("Forming new cache URL for '%s': '%s'", req_url, cache_key_url);
-              if (req_url != nullptr) {
-                TSfree(req_url);
-              }
+        txn_state = new txndata;
+        txn_state->range_value.assign(hdr_value, len);
+
+        std::string const &rv = txn_state->range_value;
+        DEBUG_LOG("txn_state->range_value: '%s'", rv.c_str());
+
+        // Consider config options
+        if (nullptr != pc) {
+          char cache_key_url[16384] = {0};
+          int cache_key_url_len     = 0;
+
+          if (pc->modify_cache_key || PS_CACHEKEY_URL == pc->ps_mode) {
+            int url_len         = 0;
+            char *const req_url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_len);
+            cache_key_url_len   = snprintf(cache_key_url, sizeof(cache_key_url), "%s-%s", req_url, rv.c_str());
+            DEBUG_LOG("Forming new cache URL for '%s': '%.*s'", req_url, cache_key_url_len, cache_key_url);
+            if (req_url != nullptr) {
+              TSfree(req_url);
             }
+          }
 
-            // set the cache key if configured to.
-            if (pc->modify_cache_key) {
-              if (TS_SUCCESS == TSCacheUrlSet(txnp, cache_key_url, cache_key_url_length)) {
-                DEBUG_LOG("Setting cache key to '%s'", cache_key_url);
-              } else {
-                ERROR_LOG("failed to change the cache url to '%s'", cache_key_url);
-                ERROR_LOG("Disabling cache for this transaction to avoid cache poisoning.");
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
-                TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
-              }
+          // Modify the cache_key
+          if (pc->modify_cache_key) {
+            DEBUG_LOG("Setting cache key to '%.*s'", cache_key_url_len, cache_key_url);
+            if (TS_SUCCESS != TSCacheUrlSet(txnp, cache_key_url, cache_key_url_len)) {
+              ERROR_LOG("Failed to change the cache url, disabling cache for this transaction to avoid cache poisoning.");
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
+              TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
             }
+          }
 
-            // Optionally set the parent_selection_url to the cache_key url or path
-            if (PS_DEFAULT != pc->ps_mode) {
-              TSMLoc ps_loc = nullptr;
-
-              if (PS_CACHEKEY_URL == pc->ps_mode) {
-                const char *start = cache_key_url;
-                const char *end   = cache_key_url + cache_key_url_length;
-                if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc) &&
-                    TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end) && // This should always succeed.
-                    TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp, hdr_buf, ps_loc)) {
-                  DEBUG_LOG("Setting Parent Selection URL to '%s'", cache_key_url);
-                  TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
-                }
+          // Set the parent_selection_url to the modified cache_key.
+          if (PS_CACHEKEY_URL == pc->ps_mode) {
+            TSMLoc ps_loc     = TS_NULL_MLOC;
+            const char *start = cache_key_url;
+            const char *end   = cache_key_url + cache_key_url_len;
+            if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc)) {
+              if (TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end) && // This should always succeed.
+                  TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp, hdr_buf, ps_loc)) {
+                DEBUG_LOG("Setting Parent Selection URL to '%.*s'", cache_key_url_len, cache_key_url);
               }
+              TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
             }
+          }
 
-            // optionally consider an X-CRR-IMS header
-            if (pc->consider_ims_header) {
-              TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, X_IMS_HEADER.data(), X_IMS_HEADER.size());
-              if (TS_NULL_MLOC != imsloc) {
-                time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf, hdr_loc, imsloc);
-                DEBUG_LOG("Servicing the '%.*s' header", (int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
-                TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
-                if (0 < itime) {
-                  txn_state->ims_time = itime;
-                }
+          // optionally consider an X-CRR-IMS header
+          if (pc->consider_ims_header) {
+            TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, X_IMS_HEADER.data(), X_IMS_HEADER.size());
+            if (TS_NULL_MLOC != imsloc) {
+              time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf, hdr_loc, imsloc);
+              DEBUG_LOG("Servicing the '%.*s' header", (int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
+              TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
+              if (0 < itime) {
+                txn_state->ims_time = itime;
               }
             }
-
-            txn_state->verify_cacheability = pc->verify_cacheability;
           }
 
-          // remove the range request header.
-          if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE) > 0) {
-            DEBUG_LOG("Removed the Range: header from the request.");
-          }
+          txn_state->verify_cacheability = pc->verify_cacheability;
+        }
 
-          TSContDataSet(txn_contp, txn_state);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, txn_contp);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, txn_contp);
-          TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, txn_contp);
-          DEBUG_LOG("Added TS_HTTP_SEND_REQUEST_HDR_HOOK, TS_HTTP_SEND_RESPONSE_HDR_HOOK, and TS_HTTP_TXN_CLOSE_HOOK");
+        // remove the range request header.
+        if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE) > 0) {
+          DEBUG_LOG("Removed the Range: header from the request.");
+        }
 
-          if (0 < txn_state->ims_time) {
-            TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, txn_contp);
-            DEBUG_LOG("Also Added TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK");
-          }
+        // Set up the continuation
+        TSCont const txn_contp = TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr);

Review comment:
       thanks




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org