2 * Copyright (C) 1996-2016 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"
14 #include "SquidString.h"
21 /* http byte-range-spec */
23 class HttpHdrRangeSpec
25 MEMPROXY_CLASS(HttpHdrRangeSpec
);
28 typedef Range
<int64_t, uint64_t> HttpRange
;
29 static int64_t const UnknownPosition
;
32 static HttpHdrRangeSpec
*Create(const char *field
, int fieldLen
);
34 bool parseInit(const char *field
, int flen
);
35 int canonize(int64_t clen
);
36 void outputInfo( char const *note
) const;
37 void packInto(Packable
* p
) const;
38 bool mergeWith(const HttpHdrRangeSpec
* donor
);
44 * There may be more than one byte range specified in the request.
45 * This object holds all range specs in order of their appearence
46 * in the request because we SHOULD preserve that order.
50 MEMPROXY_CLASS(HttpHdrRange
);
53 static size_t ParsedCount
;
54 /* Http Range Header Field */
55 static HttpHdrRange
*ParseCreate(const String
* range_spec
);
58 HttpHdrRange(HttpHdrRange
const &);
60 HttpHdrRange
&operator= (HttpHdrRange
const &);
62 typedef std::vector
<HttpHdrRangeSpec
*>::iterator iterator
;
63 typedef std::vector
<HttpHdrRangeSpec
*>::const_iterator const_iterator
;
65 const_iterator
begin () const;
67 const_iterator
end() const;
69 /* adjust specs after the length is known */
70 int canonize(int64_t);
71 int canonize(HttpReply
*rep
);
72 /* returns true if ranges are valid; inits HttpHdrRange */
73 bool parseInit(const String
* range_spec
);
74 void packInto(Packable
* p
) const;
76 bool isComplex() const;
77 bool willBeComplex() const;
78 int64_t firstOffset() const;
79 int64_t lowestOffset(int64_t) const;
80 bool offsetLimitExceeded(const int64_t limit
) const;
81 bool contains(HttpHdrRangeSpec
& r
) const;
82 std::vector
<HttpHdrRangeSpec
*> specs
;
85 void getCanonizedSpecs (std::vector
<HttpHdrRangeSpec
*> ©
);
86 void merge (std::vector
<HttpHdrRangeSpec
*> &basis
);
91 * Data for iterating thru range specs
93 class HttpHdrRangeIter
97 HttpHdrRange::iterator pos
;
98 HttpHdrRange::iterator end
;
99 const HttpHdrRangeSpec
*currentSpec() const;
101 int64_t debt() const;
103 int64_t debt_size
; /* bytes left to send from the current spec */
104 String boundary
; /* boundary for multipart responses */
108 #endif /* SQUID_HTTPHEADERRANGE_H */