2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_HTTPHEADERRANGE_H
10 #define SQUID_HTTPHEADERRANGE_H
12 #include "base/Range.h"
13 #include "mem/forward.h"
14 #include "SquidString.h"
21 // TODO: Refactor to disambiguate and provide message-specific APIs.
22 /// either byte-range-spec (in a request Range header)
23 /// or suffix-byte-range-spec (in a request Range header)
24 /// or byte-range part of byte-range-resp (in a response Content-Range header)
25 /// or "*" part of unsatisfied-range (in a response Content-Range header)
26 class HttpHdrRangeSpec
28 MEMPROXY_CLASS(HttpHdrRangeSpec
);
31 typedef Range
<int64_t, uint64_t> HttpRange
;
32 static int64_t const UnknownPosition
;
35 static HttpHdrRangeSpec
*Create(const char *field
, int fieldLen
);
37 bool parseInit(const char *field
, int flen
);
38 int canonize(int64_t clen
);
39 void outputInfo( char const *note
) const;
40 void packInto(Packable
* p
) const;
41 bool mergeWith(const HttpHdrRangeSpec
* donor
);
47 * There may be more than one byte range specified in the request.
48 * This object holds all range specs in order of their appearance
49 * in the request because we SHOULD preserve that order.
53 MEMPROXY_CLASS(HttpHdrRange
);
56 static size_t ParsedCount
;
57 /* Http Range Header Field */
58 static HttpHdrRange
*ParseCreate(const String
* range_spec
);
61 HttpHdrRange(HttpHdrRange
const &);
63 HttpHdrRange
&operator= (HttpHdrRange
const &);
65 typedef std::vector
<HttpHdrRangeSpec
*>::iterator iterator
;
66 typedef std::vector
<HttpHdrRangeSpec
*>::const_iterator const_iterator
;
68 const_iterator
begin () const;
70 const_iterator
end() const;
72 /* adjust specs after the length is known */
73 int canonize(int64_t);
74 int canonize(HttpReply
*rep
);
75 /* returns true if ranges are valid; inits HttpHdrRange */
76 bool parseInit(const String
* range_spec
);
77 void packInto(Packable
* p
) const;
79 bool isComplex() const;
80 bool willBeComplex() const;
81 int64_t firstOffset() const;
82 int64_t lowestOffset(int64_t) const;
83 bool offsetLimitExceeded(const int64_t limit
) const;
84 std::vector
<HttpHdrRangeSpec
*> specs
;
87 void getCanonizedSpecs (std::vector
<HttpHdrRangeSpec
*> ©
);
88 void merge (std::vector
<HttpHdrRangeSpec
*> &basis
);
93 * Data for iterating thru range specs
95 class HttpHdrRangeIter
99 HttpHdrRange::iterator pos
;
100 HttpHdrRange::iterator end
;
101 const HttpHdrRangeSpec
*currentSpec() const;
103 int64_t debt() const;
105 int64_t debt_size
= 0; /* bytes left to send from the current spec */
106 String boundary
; /* boundary for multipart responses */
110 #endif /* SQUID_HTTPHEADERRANGE_H */