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

bcall 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 54d44fc863 Use slice req method type in Data obj (#10925)
54d44fc863 is described below

commit 54d44fc86367ba3fbb0a0e5de75d498fb15aa3fe
Author: Serris Lew <serrisn...@gmail.com>
AuthorDate: Mon Dec 18 09:24:10 2023 -0800

    Use slice req method type in Data obj (#10925)
    
    * Save slice req method type in Data obj
    
    * refactor request_block code
    
    * bypass vio logic for PURGE
    
    ---------
    
    Co-authored-by: Serris Lew <lser...@apple.com>
    (cherry picked from commit db7e10542a3bc928c26e4ed1cdf81e7a01ccbb7d)
---
 plugins/experimental/slice/Config.h  | 12 ++----------
 plugins/experimental/slice/Data.h    |  9 +++++++++
 plugins/experimental/slice/server.cc | 25 ++++++++++++++-----------
 plugins/experimental/slice/slice.cc  |  6 ++----
 plugins/experimental/slice/util.cc   |  2 +-
 5 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/plugins/experimental/slice/Config.h 
b/plugins/experimental/slice/Config.h
index 430495333a..fe409e6866 100644
--- a/plugins/experimental/slice/Config.h
+++ b/plugins/experimental/slice/Config.h
@@ -45,9 +45,8 @@ struct Config {
   int m_paceerrsecs{0};   // -1 disable logging, 0 no pacing, max 60s
   int m_prefetchcount{0}; // 0 disables prefetching
   enum RefType { First, Relative };
-  RefType m_reftype{First};           // reference slice is relative to request
-  const char *m_method_type{nullptr}; // type of header request
-  bool m_head_strip_range{false};     // strip range header for head requests
+  RefType m_reftype{First};       // reference slice is relative to request
+  bool m_head_strip_range{false}; // strip range header for head requests
 
   std::string m_skip_header;
   std::string m_crr_ims_header;
@@ -71,13 +70,6 @@ struct Config {
     return None != m_regex_type;
   }
 
-  // Check if response only expects header
-  bool
-  onlyHeader() const
-  {
-    return (m_method_type == TS_HTTP_METHOD_HEAD || m_method_type == 
TS_HTTP_METHOD_PURGE);
-  }
-
   // If no null reg, true, otherwise check against regex
   bool matchesRegex(char const *const url, int const urllen) const;
 
diff --git a/plugins/experimental/slice/Data.h 
b/plugins/experimental/slice/Data.h
index 8e654a69bc..5cd7e8538f 100644
--- a/plugins/experimental/slice/Data.h
+++ b/plugins/experimental/slice/Data.h
@@ -71,6 +71,8 @@ struct Data {
 
   TSHttpStatus m_statustype{TS_HTTP_STATUS_NONE}; // 200 or 206
 
+  const char *m_method_type{nullptr}; // type of header request
+
   Range m_req_range; // converted to half open interval
 
   int64_t m_blocknum{-1};     // block number to work on, -1 bad/stop
@@ -108,6 +110,13 @@ struct Data {
     m_lastmodified[0] = '\0';
   }
 
+  // Check if response only expects header
+  bool
+  onlyHeader() const
+  {
+    return (m_method_type == TS_HTTP_METHOD_HEAD || m_method_type == 
TS_HTTP_METHOD_PURGE);
+  }
+
   ~Data()
   {
     if (nullptr != m_urlbuf) {
diff --git a/plugins/experimental/slice/server.cc 
b/plugins/experimental/slice/server.cc
index ba342d862e..3df401240e 100644
--- a/plugins/experimental/slice/server.cc
+++ b/plugins/experimental/slice/server.cc
@@ -111,7 +111,7 @@ handleFirstServerHeader(Data *const data, TSCont const 
contp)
     // Should run TSVIONSetBytes(output_io, hlen + bodybytes);
     int64_t const hlen = TSHttpHdrLengthGet(header.m_buffer, header.m_lochdr);
     int64_t const clen = contentLengthFrom(header);
-    if (TS_HTTP_STATUS_OK == header.status() && data->m_config->onlyHeader()) {
+    if (TS_HTTP_STATUS_OK == header.status() && data->onlyHeader()) {
       DEBUG_LOG("HEAD/PURGE request stripped Range header: expects 200");
       data->m_bytestosend   = hlen;
       data->m_blockexpected = 0;
@@ -220,7 +220,7 @@ handleFirstServerHeader(Data *const data, TSCont const 
contp)
   int const hbytes = TSHttpHdrLengthGet(header.m_buffer, header.m_lochdr);
 
   // HEAD request only sends header
-  if (data->m_config->onlyHeader()) {
+  if (data->onlyHeader()) {
     data->m_bytestosend   = hbytes;
     data->m_blockexpected = 0;
   } else {
@@ -364,7 +364,7 @@ handleNextServerHeader(Data *const data, TSCont const contp)
 
   switch (header.status()) {
   case TS_HTTP_STATUS_NOT_FOUND:
-    if (data->m_config->onlyHeader()) {
+    if (data->onlyHeader()) {
       return false;
     }
     // need to reissue reference slice
@@ -374,7 +374,7 @@ handleNextServerHeader(Data *const data, TSCont const contp)
   case TS_HTTP_STATUS_PARTIAL_CONTENT:
     break;
   default:
-    if (data->m_config->onlyHeader() && header.status() == TS_HTTP_STATUS_OK) {
+    if (data->onlyHeader() && header.status() == TS_HTTP_STATUS_OK) {
       return true;
     }
     DEBUG_LOG("Non 206/404 internal block response encountered");
@@ -640,7 +640,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 && !data->m_config->onlyHeader()) {
+    if (0 == data->m_blockexpected && !data->onlyHeader()) {
       shutdown(contp, data); // this will crash if first block
       return;
     }
@@ -673,12 +673,15 @@ handle_server_resp(TSCont contp, TSEvent event, Data 
*const data)
     // continue processing blocks if more requests need to be made
     // HEAD requests only has one slice block
     if (data->m_req_range.blockIsInside(data->m_config->m_blockbytes, 
data->m_blocknum) &&
-        data->m_config->m_method_type != TS_HTTP_METHOD_HEAD) {
+        data->m_method_type != TS_HTTP_METHOD_HEAD) {
       // Don't immediately request the next slice if the client
       // isn't keeping up
 
-      bool start_next_block = true;
-      if (data->m_dnstream.m_write.isOpen()) {
+      bool start_next_block = false;
+      if (data->m_method_type == TS_HTTP_METHOD_PURGE) {
+        // for PURGE requests, clients won't request more data (no body 
content)
+        start_next_block = true;
+      } else if (data->m_dnstream.m_write.isOpen()) {
         // check throttle condition
         TSVIO const output_vio    = data->m_dnstream.m_write.m_vio;
         int64_t const output_done = TSVIONDoneGet(output_vio);
@@ -686,10 +689,10 @@ handle_server_resp(TSCont contp, TSEvent event, Data 
*const data)
         int64_t const threshout   = data->m_config->m_blockbytes;
         int64_t const buffered    = output_sent - output_done;
 
-        // for PURGE requests, clients won't request more data (no body 
content)
-        if (threshout < buffered && !data->m_config->onlyHeader()) {
-          start_next_block = false;
+        if (threshout < buffered) {
           DEBUG_LOG("%p handle_server_resp: throttling %" PRId64, data, 
buffered);
+        } else {
+          start_next_block = true;
         }
       }
       if (start_next_block) {
diff --git a/plugins/experimental/slice/slice.cc 
b/plugins/experimental/slice/slice.cc
index 09d2847383..1989116330 100644
--- a/plugins/experimental/slice/slice.cc
+++ b/plugins/experimental/slice/slice.cc
@@ -50,9 +50,6 @@ read_request(TSHttpTxn txnp, Config *const config)
         return false;
       }
 
-      // set header method config to only expect header response
-      config->m_method_type = header.method();
-
       if (config->hasRegex()) {
         int urllen         = 0;
         char *const urlstr = TSHttpTxnEffectiveUrlStringGet(txnp, &urllen);
@@ -84,7 +81,8 @@ read_request(TSHttpTxn txnp, Config *const config)
       TSAssert(nullptr != config);
       Data *const data = new Data(config);
 
-      data->m_txnp = txnp;
+      data->m_method_type = header.method();
+      data->m_txnp        = txnp;
 
       // set up feedback connect
       if (AF_INET == ip->sa_family) {
diff --git a/plugins/experimental/slice/util.cc 
b/plugins/experimental/slice/util.cc
index 71d99b9869..c4d9a314e8 100644
--- a/plugins/experimental/slice/util.cc
+++ b/plugins/experimental/slice/util.cc
@@ -80,7 +80,7 @@ request_block(TSCont contp, Data *const data)
   HttpHeader header(data->m_req_hdrmgr.m_buffer, data->m_req_hdrmgr.m_lochdr);
 
   // if configured, remove range header from head requests
-  if (data->m_config->m_method_type == TS_HTTP_METHOD_HEAD && 
data->m_config->m_head_strip_range) {
+  if (data->m_method_type == TS_HTTP_METHOD_HEAD && 
data->m_config->m_head_strip_range) {
     header.removeKey(TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
   } else {
     // add/set sub range key and add slicer tag

Reply via email to