You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2022/08/31 14:02:39 UTC

[trafficserver] branch 9.2.x updated: Add HEAD requests to slice plugin (#9061)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new fc62af9ef Add HEAD requests to slice plugin (#9061)
fc62af9ef is described below

commit fc62af9ef70a51c318f4a7c0b8f674c341e2931c
Author: Serris Lew <se...@gmail.com>
AuthorDate: Tue Aug 30 16:42:23 2022 -0600

    Add HEAD requests to slice plugin (#9061)
    
    Co-authored-by: Serris Lew <ls...@apple.com>
    (cherry picked from commit 40ad425131ce3caf676eaf7582e219b5b846955a)
---
 plugins/experimental/slice/Config.h  |  1 +
 plugins/experimental/slice/server.cc | 17 +++++++++++------
 plugins/experimental/slice/slice.cc  |  7 +++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/plugins/experimental/slice/Config.h b/plugins/experimental/slice/Config.h
index 8408ffc20..d1dceb99e 100644
--- a/plugins/experimental/slice/Config.h
+++ b/plugins/experimental/slice/Config.h
@@ -45,6 +45,7 @@ struct Config {
   int m_prefetchcount{0}; // 0 disables prefetching
   enum RefType { First, Relative };
   RefType m_reftype{First}; // reference slice is relative to request
+  bool m_head_req{false};   // HEAD request
 
   std::string m_skip_header;
   std::string m_crr_ims_header;
diff --git a/plugins/experimental/slice/server.cc b/plugins/experimental/slice/server.cc
index a25376bc9..2d4c1d812 100644
--- a/plugins/experimental/slice/server.cc
+++ b/plugins/experimental/slice/server.cc
@@ -174,9 +174,6 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
   data->m_lastmodifiedlen = sizeof(data->m_lastmodified);
   header.valueForKey(TS_MIME_FIELD_LAST_MODIFIED, TS_MIME_LEN_LAST_MODIFIED, data->m_lastmodified, &data->m_lastmodifiedlen);
 
-  // size of the first block payload
-  data->m_blockexpected = blockcr.rangeSize();
-
   // Now we can set up the expected client response
   if (TS_HTTP_STATUS_PARTIAL_CONTENT == data->m_statustype) {
     ContentRange respcr;
@@ -212,8 +209,16 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
   // add the response header length to the total bytes to send
   int const hbytes = TSHttpHdrLengthGet(header.m_buffer, header.m_lochdr);
 
-  TSVIONBytesSet(output_vio, hbytes + bodybytes);
-  data->m_bytestosend = hbytes + bodybytes;
+  // HEAD request only sends header
+  if (data->m_config->m_head_req) {
+    data->m_bytestosend   = hbytes;
+    data->m_blockexpected = 0;
+  } else {
+    // GET request sends header + object
+    data->m_bytestosend   = hbytes + bodybytes;
+    data->m_blockexpected = blockcr.rangeSize();
+  }
+  TSVIONBytesSet(output_vio, data->m_bytestosend);
   TSHttpHdrPrint(header.m_buffer, header.m_lochdr, output_buf);
   data->m_bytessent = hbytes;
   TSVIOReenable(output_vio);
@@ -613,7 +618,7 @@ handle_server_resp(TSCont contp, TSEvent event, Data *const data)
     // corner condition, good source header + 0 length aborted content
     // results in no header being read, just an EOS.
     // trying to delete the upstream will crash ATS (??)
-    if (0 == data->m_blockexpected) {
+    if (0 == data->m_blockexpected && !data->m_config->m_head_req) {
       shutdown(contp, data); // this will crash if first block
       return;
     }
diff --git a/plugins/experimental/slice/slice.cc b/plugins/experimental/slice/slice.cc
index abb1630fc..90477ce2f 100644
--- a/plugins/experimental/slice/slice.cc
+++ b/plugins/experimental/slice/slice.cc
@@ -41,7 +41,7 @@ read_request(TSHttpTxn txnp, Config *const config)
   hdrmgr.populateFrom(txnp, TSHttpTxnClientReqGet);
   HttpHeader const header(hdrmgr.m_buffer, hdrmgr.m_lochdr);
 
-  if (TS_HTTP_METHOD_GET == header.method()) {
+  if (TS_HTTP_METHOD_GET == header.method() || TS_HTTP_METHOD_HEAD == header.method()) {
     if (!header.hasKey(config->m_skip_header.data(), config->m_skip_header.size())) {
       // check if any previous plugin has monkeyed with the transaction status
       TSHttpStatus const txnstat = TSHttpTxnStatusGet(txnp);
@@ -50,6 +50,9 @@ read_request(TSHttpTxn txnp, Config *const config)
         return false;
       }
 
+      // set HEAD config to only expect header response
+      config->m_head_req = (TS_HTTP_METHOD_HEAD == header.method());
+
       if (config->hasRegex()) {
         int urllen         = 0;
         char *const urlstr = TSHttpTxnEffectiveUrlStringGet(txnp, &urllen);
@@ -183,7 +186,7 @@ read_request(TSHttpTxn txnp, Config *const config)
 
       return true;
     } else {
-      DEBUG_LOG("slice passing GET request through to next plugin");
+      DEBUG_LOG("slice passing GET or HEAD request through to next plugin");
     }
   }