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 2021/02/22 17:00:40 UTC
[trafficserver] 01/02: slice/handleFirstServerHeader: return sooner
on requested range errors (#7486)
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 1d9eaedbb527e746877a91ebb9410f4bcc24448d
Author: Brian Olsen <bn...@gmail.com>
AuthorDate: Fri Feb 12 11:51:15 2021 -0700
slice/handleFirstServerHeader: return sooner on requested range errors (#7486)
(cherry picked from commit df01ace2b0bdffd3ddcc5b2c7587b6d6fed5234c)
---
plugins/experimental/slice/Range.h | 2 +-
plugins/experimental/slice/server.cc | 16 +++++-----------
tests/gold_tests/pluginTest/slice/slice.test.py | 9 +++++++++
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/plugins/experimental/slice/Range.h b/plugins/experimental/slice/Range.h
index ba581c6..44ef1de 100644
--- a/plugins/experimental/slice/Range.h
+++ b/plugins/experimental/slice/Range.h
@@ -29,7 +29,7 @@
struct Range {
public:
- static int64_t constexpr maxval = (std::numeric_limits<int64_t>::max() >> 2);
+ static int64_t constexpr maxval = (std::numeric_limits<int64_t>::max() / 2);
int64_t m_beg{-1};
int64_t m_end{-1}; // half open
diff --git a/plugins/experimental/slice/server.cc b/plugins/experimental/slice/server.cc
index 089b1fc..510edab 100644
--- a/plugins/experimental/slice/server.cc
+++ b/plugins/experimental/slice/server.cc
@@ -91,8 +91,6 @@ enum HeaderState {
HeaderState
handleFirstServerHeader(Data *const data, TSCont const contp)
{
- HeaderState state = HeaderState::Good;
-
HttpHeader header(data->m_resp_hdrmgr.m_buffer, data->m_resp_hdrmgr.m_lochdr);
if (TSIsDebugTagSet(PLUGIN_NAME)) {
@@ -119,8 +117,7 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
TSVIONBytesSet(output_vio, clen);
}
TSHttpHdrPrint(header.m_buffer, header.m_lochdr, output_buf);
- state = HeaderState::Passthru;
- return state;
+ return HeaderState::Passthru;
}
ContentRange const blockcr = contentRangeFrom(header);
@@ -131,8 +128,7 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
TSVIONBytesSet(output_vio, msg502.size());
TSIOBufferWrite(output_buf, msg502.data(), msg502.size());
TSVIOReenable(output_vio);
- state = HeaderState::Fail;
- return state;
+ return HeaderState::Fail;
}
// set the resource content length from block response
@@ -163,10 +159,8 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
TSHttpHdrPrint(header.m_buffer, header.m_lochdr, output_buf);
TSIOBufferWrite(output_buf, bodystr.data(), bodystr.size());
TSVIOReenable(output_vio);
-
data->m_upstream.m_read.close();
-
- state = HeaderState::Fail;
+ return HeaderState::Fail;
}
// save data header string
@@ -199,7 +193,7 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
data->m_dnstream.close();
ERROR_LOG("Bad/invalid response content range");
- state = HeaderState::Fail;
+ return HeaderState::Fail;
}
header.setKeyVal(TS_MIME_FIELD_CONTENT_RANGE, TS_MIME_LEN_CONTENT_RANGE, rangestr, rangelen);
@@ -223,7 +217,7 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
data->m_bytessent = hbytes;
TSVIOReenable(output_vio);
- return state;
+ return HeaderState::Good;
}
void
diff --git a/tests/gold_tests/pluginTest/slice/slice.test.py b/tests/gold_tests/pluginTest/slice/slice.test.py
index 7bda378..7dfadbf 100644
--- a/tests/gold_tests/pluginTest/slice/slice.test.py
+++ b/tests/gold_tests/pluginTest/slice/slice.test.py
@@ -171,3 +171,12 @@ ps.Streams.stderr = "gold/slice_mid.stderr.gold"
ps.Streams.stdout.Content = Testers.ContainsExpression("206 Partial Content", "expected 206 response")
ps.Streams.stdout.Content += Testers.ContainsExpression("Content-Range: bytes 5-16/18", "mismatch byte content response")
tr.StillRunningAfter = ts
+
+# 8 Test - special case, begin inside last slice block but outside asset len
+tr = Test.AddTestRun("Invalid end range request, 416")
+beg = len(body) + 1
+end = beg + block_bytes
+ps = tr.Processes.Default
+ps.Command = curl_and_args + ' http://slice/path' + ' -r {}-{}'.format(beg, end)
+ps.Streams.stdout.Content = Testers.ContainsExpression("416 Requested Range Not Satisfiable", "expected 416 response")
+tr.StillRunningAfter = ts