2 * Copyright (C) 1996-2015 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 "mem/forward.h"
15 #include "SquidString.h"
20 /* http byte-range-spec */
22 class HttpHdrRangeSpec
24 MEMPROXY_CLASS(HttpHdrRangeSpec
);
27 typedef Range
<int64_t, uint64_t> HttpRange
;
28 static int64_t const UnknownPosition
;
31 static HttpHdrRangeSpec
*Create(const char *field
, int fieldLen
);
33 bool parseInit(const char *field
, int flen
);
34 int canonize(int64_t clen
);
35 void outputInfo( char const *note
) const;
36 void packInto(Packer
* p
) const;
37 bool mergeWith(const HttpHdrRangeSpec
* donor
);
43 * There may be more than one byte range specified in the request.
44 * This object holds all range specs in order of their appearence
45 * in the request because we SHOULD preserve that order.
49 MEMPROXY_CLASS(HttpHdrRange
);
52 static size_t ParsedCount
;
53 /* Http Range Header Field */
54 static HttpHdrRange
*ParseCreate(const String
* range_spec
);
57 HttpHdrRange(HttpHdrRange
const &);
59 HttpHdrRange
&operator= (HttpHdrRange
const &);
61 typedef std::vector
<HttpHdrRangeSpec
*>::iterator iterator
;
62 typedef std::vector
<HttpHdrRangeSpec
*>::const_iterator const_iterator
;
64 const_iterator
begin () const;
66 const_iterator
end() const;
68 /* adjust specs after the length is known */
69 int canonize(int64_t);
70 int canonize(HttpReply
*rep
);
71 /* returns true if ranges are valid; inits HttpHdrRange */
72 bool parseInit(const String
* range_spec
);
73 void packInto(Packer
* p
) const;
75 bool isComplex() const;
76 bool willBeComplex() const;
77 int64_t firstOffset() const;
78 int64_t lowestOffset(int64_t) const;
79 bool offsetLimitExceeded(const int64_t limit
) const;
80 bool contains(HttpHdrRangeSpec
& r
) const;
81 std::vector
<HttpHdrRangeSpec
*> specs
;
84 void getCanonizedSpecs (std::vector
<HttpHdrRangeSpec
*> ©
);
85 void merge (std::vector
<HttpHdrRangeSpec
*> &basis
);
90 * Data for iterating thru range specs
92 class HttpHdrRangeIter
96 HttpHdrRange::iterator pos
;
97 HttpHdrRange::iterator end
;
98 const HttpHdrRangeSpec
*currentSpec() const;
100 int64_t debt() const;
102 int64_t debt_size
; /* bytes left to send from the current spec */
103 String boundary
; /* boundary for multipart responses */
107 #endif /* SQUID_HTTPHEADERRANGE_H */