Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/experimental/slice/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why this is being changed from max / 4 to max / 2, or really why it's not just max. But I'll take it on faith.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it just has to be sufficiently large but not max64.


int64_t m_beg{-1};
int64_t m_end{-1}; // half open
Expand Down
16 changes: 5 additions & 11 deletions plugins/experimental/slice/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably get optimized out but it's worthwhile cleanup.

}

ContentRange const blockcr = contentRangeFrom(header);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -223,7 +217,7 @@ handleFirstServerHeader(Data *const data, TSCont const contp)
data->m_bytessent = hbytes;
TSVIOReenable(output_vio);

return state;
return HeaderState::Good;
}

void
Expand Down
9 changes: 9 additions & 0 deletions tests/gold_tests/pluginTest/slice/slice.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,12 @@
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