++p;
- if (*p == '*')
+ if (*p == '*') {
+ if (!known_spec(range->spec.offset)) {
+ debugs(68, 2, "invalid (*/*) content-range-spec near: '" << str << "'");
+ return 0;
+ }
range->elength = range_spec_unknown;
- else if (!httpHeaderParseOffset(p, &range->elength))
+ } else if (!httpHeaderParseOffset(p, &range->elength))
return 0;
else if (range->elength <= 0) {
/* Additional paranoidal check for BUG2155 - entity-length MUST be > 0 */
return 0;
}
+ // reject unsatisfied-range and such; we only use well-defined ranges today
+ if (!known_spec(range->spec.offset) || !known_spec(range->spec.length)) {
+ debugs(68, 2, "unwanted content-range-spec near: '" << str << "'");
+ return 0;
+ }
+
debugs(68, 8, "parsed content-range field: " <<
(long int) range->spec.offset << "-" <<
(long int) range->spec.offset + range->spec.length - 1 << " / " <<
class HttpReply;
class Packable;
-/* http byte-range-spec */
-
+// TODO: Refactor to disambiguate and provide message-specific APIs.
+/// either byte-range-spec (in a request Range header)
+/// or suffix-byte-range-spec (in a request Range header)
+/// or byte-range part of byte-range-resp (in a response Content-Range header)
+/// or "*" part of unsatisfied-range (in a response Content-Range header)
class HttpHdrRangeSpec
{
MEMPROXY_CLASS(HttpHdrRangeSpec);
maybePurgeOthers();
// adaptation may overwrite old offset computed using the virgin response
- const bool partial = theFinalReply->contentRange();
- currentOffset = partial ? theFinalReply->contentRange()->spec.offset : 0;
+ currentOffset = 0;
+ if (const auto cr = theFinalReply->contentRange()) {
+ if (cr->spec.offset != HttpHdrRangeSpec::UnknownPosition)
+ currentOffset = cr->spec.offset;
+ }
}
/// whether to prevent caching of an otherwise cachable response
return start;
}
- } else if (reply && reply->contentRange()) {
+ } else if (const auto cr = reply ? reply->contentRange() : nullptr) {
/* request does not have ranges, but reply does */
/* TODO: should use range_iter_pos on reply, as soon as reply->content_range
* becomes HttpHdrRange rather than HttpHdrRangeSpec.
*/
- return http->out.offset + reply->contentRange()->spec.offset;
+ if (cr->spec.offset != HttpHdrRangeSpec::UnknownPosition)
+ return http->out.offset + cr->spec.offset;
}
return http->out.offset;
// did we get at least what we expected, based on range specs?
+ // this Content-Range does not tell us how many bytes to expect
+ if (bytesExpected == HttpHdrRangeSpec::UnknownPosition)
+ return STREAM_NONE;
+
if (bytesSent == bytesExpected) // got everything
return STREAM_COMPLETE;