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