]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderRange.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpHeaderRange.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_HTTPHEADERRANGE_H
10 #define SQUID_HTTPHEADERRANGE_H
11
12 #include "mem/forward.h"
13 #include "Packer.h"
14 #include "Range.h"
15 #include "SquidString.h"
16
17 #include <vector>
18
19 class HttpReply;
20 /* http byte-range-spec */
21
22 class HttpHdrRangeSpec
23 {
24 MEMPROXY_CLASS(HttpHdrRangeSpec);
25
26 public:
27 typedef Range<int64_t, uint64_t> HttpRange;
28 static int64_t const UnknownPosition;
29
30 HttpHdrRangeSpec();
31 static HttpHdrRangeSpec *Create(const char *field, int fieldLen);
32
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);
38 int64_t offset;
39 int64_t length;
40 };
41
42 /**
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.
46 */
47 class HttpHdrRange
48 {
49 MEMPROXY_CLASS(HttpHdrRange);
50
51 public:
52 static size_t ParsedCount;
53 /* Http Range Header Field */
54 static HttpHdrRange *ParseCreate(const String * range_spec);
55
56 HttpHdrRange();
57 HttpHdrRange(HttpHdrRange const &);
58 ~HttpHdrRange();
59 HttpHdrRange &operator= (HttpHdrRange const &);
60
61 typedef std::vector<HttpHdrRangeSpec *>::iterator iterator;
62 typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator;
63 iterator begin();
64 const_iterator begin () const;
65 iterator end();
66 const_iterator end() const;
67
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;
74 /* other */
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;
82
83 private:
84 void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> &copy);
85 void merge (std::vector<HttpHdrRangeSpec *> &basis);
86 int64_t clen;
87 };
88
89 /**
90 * Data for iterating thru range specs
91 */
92 class HttpHdrRangeIter
93 {
94
95 public:
96 HttpHdrRange::iterator pos;
97 HttpHdrRange::iterator end;
98 const HttpHdrRangeSpec *currentSpec() const;
99 void updateSpec();
100 int64_t debt() const;
101 void debt(int64_t);
102 int64_t debt_size; /* bytes left to send from the current spec */
103 String boundary; /* boundary for multipart responses */
104 bool valid;
105 };
106
107 #endif /* SQUID_HTTPHEADERRANGE_H */
108