]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeaderRange.h
NoNewGlobals for MapLabel (#1746)
[thirdparty/squid.git] / src / HttpHeaderRange.h
CommitLineData
528b2c61 1/*
b8ae064d 2 * Copyright (C) 1996-2023 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
ff9d9458
FC
9#ifndef SQUID_SRC_HTTPHEADERRANGE_H
10#define SQUID_SRC_HTTPHEADERRANGE_H
528b2c61 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 18class HttpReply;
0a647ffb
AJ
19class Packable;
20
6c9c44d0
AR
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)
62e76326 26class HttpHdrRangeSpec
27{
741c2986 28 MEMPROXY_CLASS(HttpHdrRangeSpec);
62e76326 29
30public:
c16f948b 31 typedef Range<int64_t, uint64_t> HttpRange;
47f6e231 32 static int64_t const UnknownPosition;
62e76326 33
528b2c61 34 HttpHdrRangeSpec();
35 static HttpHdrRangeSpec *Create(const char *field, int fieldLen);
36
37 bool parseInit(const char *field, int flen);
47f6e231 38 int canonize(int64_t clen);
528b2c61 39 void outputInfo( char const *note) const;
17802cf1 40 void packInto(Packable * p) const;
528b2c61 41 bool mergeWith(const HttpHdrRangeSpec * donor);
47f6e231 42 int64_t offset;
43 int64_t length;
528b2c61 44};
45
63be0a78 46/**
47 * There may be more than one byte range specified in the request.
2f8abb64 48 * This object holds all range specs in order of their appearance
528b2c61 49 * in the request because we SHOULD preserve that order.
50 */
62e76326 51class HttpHdrRange
52{
b001e822 53 MEMPROXY_CLASS(HttpHdrRange);
528b2c61 54
741c2986 55public:
528b2c61 56 static size_t ParsedCount;
57 /* Http Range Header Field */
30abd221 58 static HttpHdrRange *ParseCreate(const String * range_spec);
528b2c61 59
60 HttpHdrRange();
61 HttpHdrRange(HttpHdrRange const &);
62 ~HttpHdrRange();
63 HttpHdrRange &operator= (HttpHdrRange const &);
64
24a8eaae
FC
65 typedef std::vector<HttpHdrRangeSpec *>::iterator iterator;
66 typedef std::vector<HttpHdrRangeSpec *>::const_iterator const_iterator;
528b2c61 67 iterator begin();
68 const_iterator begin () const;
69 iterator end();
70 const_iterator end() const;
62e76326 71
528b2c61 72 /* adjust specs after the length is known */
47f6e231 73 int canonize(int64_t);
528b2c61 74 int canonize(HttpReply *rep);
75 /* returns true if ranges are valid; inits HttpHdrRange */
30abd221 76 bool parseInit(const String * range_spec);
17802cf1 77 void packInto(Packable * p) const;
528b2c61 78 /* other */
79 bool isComplex() const;
80 bool willBeComplex() const;
47f6e231 81 int64_t firstOffset() const;
82 int64_t lowestOffset(int64_t) const;
11e3fa1c 83 bool offsetLimitExceeded(const int64_t limit) const;
24a8eaae 84 std::vector<HttpHdrRangeSpec *> specs;
62e76326 85
528b2c61 86private:
24a8eaae
FC
87 void getCanonizedSpecs (std::vector<HttpHdrRangeSpec *> &copy);
88 void merge (std::vector<HttpHdrRangeSpec *> &basis);
47f6e231 89 int64_t clen;
528b2c61 90};
91
63be0a78 92/**
93 * Data for iterating thru range specs
94 */
62e76326 95class HttpHdrRangeIter
96{
97
98public:
528b2c61 99 HttpHdrRange::iterator pos;
24a8eaae 100 HttpHdrRange::iterator end;
528b2c61 101 const HttpHdrRangeSpec *currentSpec() const;
102 void updateSpec();
47f6e231 103 int64_t debt() const;
104 void debt(int64_t);
7024fb73 105 int64_t debt_size = 0; /* bytes left to send from the current spec */
f53969cc 106 String boundary; /* boundary for multipart responses */
7024fb73 107 bool valid = false;
528b2c61 108};
62e76326 109
ff9d9458 110#endif /* SQUID_SRC_HTTPHEADERRANGE_H */
f53969cc 111