]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 The Squid Software Foundation and contributors |
528b2c61 | 3 | * |
bbc27441 AJ |
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. | |
528b2c61 | 7 | */ |
8 | ||
9 | #ifndef SQUID_HTTPHEADERRANGE_H | |
10 | #define SQUID_HTTPHEADERRANGE_H | |
11 | ||
21dfc374 | 12 | #include "base/Range.h" |
ed6e9fb9 | 13 | #include "mem/forward.h" |
25b6a907 | 14 | #include "SquidString.h" |
528b2c61 | 15 | |
b7347197 FC |
16 | #include <vector> |
17 | ||
0353e724 | 18 | class HttpReply; |
0a647ffb AJ |
19 | class Packable; |
20 | ||
528b2c61 | 21 | /* http byte-range-spec */ |
62e76326 | 22 | |
23 | class HttpHdrRangeSpec | |
24 | { | |
741c2986 | 25 | MEMPROXY_CLASS(HttpHdrRangeSpec); |
62e76326 | 26 | |
27 | public: | |
c16f948b | 28 | typedef Range<int64_t, uint64_t> HttpRange; |
47f6e231 | 29 | static int64_t const UnknownPosition; |
62e76326 | 30 | |
528b2c61 | 31 | HttpHdrRangeSpec(); |
32 | static HttpHdrRangeSpec *Create(const char *field, int fieldLen); | |
33 | ||
34 | bool parseInit(const char *field, int flen); | |
47f6e231 | 35 | int canonize(int64_t clen); |
528b2c61 | 36 | void outputInfo( char const *note) const; |
17802cf1 | 37 | void packInto(Packable * p) const; |
528b2c61 | 38 | bool mergeWith(const HttpHdrRangeSpec * donor); |
47f6e231 | 39 | int64_t offset; |
40 | int64_t length; | |
528b2c61 | 41 | }; |
42 | ||
63be0a78 | 43 | /** |
44 | * There may be more than one byte range specified in the request. | |
528b2c61 | 45 | * This object holds all range specs in order of their appearence |
46 | * in the request because we SHOULD preserve that order. | |
47 | */ | |
62e76326 | 48 | class HttpHdrRange |
49 | { | |
b001e822 | 50 | MEMPROXY_CLASS(HttpHdrRange); |
528b2c61 | 51 | |
741c2986 | 52 | public: |
528b2c61 | 53 | static size_t ParsedCount; |
54 | /* Http Range Header Field */ | |
30abd221 | 55 | static HttpHdrRange *ParseCreate(const String * range_spec); |
528b2c61 | 56 | |
57 | HttpHdrRange(); | |
58 | HttpHdrRange(HttpHdrRange const &); | |
59 | ~HttpHdrRange(); | |
60 | HttpHdrRange &operator= (HttpHdrRange const &); | |
61 | ||
24a8eaae FC |
62 | typedef std::vector<HttpHdrRangeSpec *>::iterator iterator; |
63 | typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator; | |
528b2c61 | 64 | iterator begin(); |
65 | const_iterator begin () const; | |
66 | iterator end(); | |
67 | const_iterator end() const; | |
62e76326 | 68 | |
528b2c61 | 69 | /* adjust specs after the length is known */ |
47f6e231 | 70 | int canonize(int64_t); |
528b2c61 | 71 | int canonize(HttpReply *rep); |
72 | /* returns true if ranges are valid; inits HttpHdrRange */ | |
30abd221 | 73 | bool parseInit(const String * range_spec); |
17802cf1 | 74 | void packInto(Packable * p) const; |
528b2c61 | 75 | /* other */ |
76 | bool isComplex() const; | |
77 | bool willBeComplex() const; | |
47f6e231 | 78 | int64_t firstOffset() const; |
79 | int64_t lowestOffset(int64_t) const; | |
11e3fa1c | 80 | bool offsetLimitExceeded(const int64_t limit) const; |
8341f96d | 81 | bool contains(const HttpHdrRangeSpec& r) const; |
24a8eaae | 82 | std::vector<HttpHdrRangeSpec *> specs; |
62e76326 | 83 | |
528b2c61 | 84 | private: |
24a8eaae FC |
85 | void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> ©); |
86 | void merge (std::vector<HttpHdrRangeSpec *> &basis); | |
47f6e231 | 87 | int64_t clen; |
528b2c61 | 88 | }; |
89 | ||
63be0a78 | 90 | /** |
91 | * Data for iterating thru range specs | |
92 | */ | |
62e76326 | 93 | class HttpHdrRangeIter |
94 | { | |
95 | ||
96 | public: | |
528b2c61 | 97 | HttpHdrRange::iterator pos; |
24a8eaae | 98 | HttpHdrRange::iterator end; |
528b2c61 | 99 | const HttpHdrRangeSpec *currentSpec() const; |
100 | void updateSpec(); | |
47f6e231 | 101 | int64_t debt() const; |
102 | void debt(int64_t); | |
f53969cc SM |
103 | int64_t debt_size; /* bytes left to send from the current spec */ |
104 | String boundary; /* boundary for multipart responses */ | |
528b2c61 | 105 | bool valid; |
106 | }; | |
62e76326 | 107 | |
528b2c61 | 108 | #endif /* SQUID_HTTPHEADERRANGE_H */ |
f53969cc | 109 |