]>
Commit | Line | Data |
---|---|---|
e6ccf245 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
e6ccf245 | 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. | |
e6ccf245 | 7 | */ |
8 | ||
9 | #ifndef SQUID_HTTPHEADER_H | |
10 | #define SQUID_HTTPHEADER_H | |
11 | ||
1139d406 | 12 | #include "http/RegisteredHeaders.h" |
528b2c61 | 13 | /* because we pass a spec by value */ |
25b6a907 | 14 | #include "HttpHeaderMask.h" |
ed6e9fb9 | 15 | #include "mem/forward.h" |
71b673d4 | 16 | #include "SquidString.h" |
43ca19e0 | 17 | |
b7347197 FC |
18 | #include <vector> |
19 | ||
696a257c | 20 | /* class forward declarations */ |
696a257c | 21 | class HttpHdrCc; |
71b673d4 | 22 | class HttpHdrContRange; |
696a257c | 23 | class HttpHdrRange; |
71b673d4 | 24 | class HttpHdrSc; |
43ca19e0 | 25 | class Packer; |
f734cda2 | 26 | class StoreEntry; |
e7ce227f | 27 | class SBuf; |
696a257c | 28 | |
63be0a78 | 29 | /** possible types for http header fields */ |
25b6a907 | 30 | typedef enum { |
f53969cc | 31 | ftInvalid = HDR_ENUM_END, /**< to catch nasty errors with hdr_id<->fld_type clashes */ |
25b6a907 | 32 | ftInt, |
47f6e231 | 33 | ftInt64, |
25b6a907 | 34 | ftStr, |
35 | ftDate_1123, | |
36 | ftETag, | |
37 | ftPCc, | |
38 | ftPContRange, | |
39 | ftPRange, | |
40 | ftPSc, | |
41 | ftDate_1123_or_ETag | |
42 | } field_type; | |
43 | ||
63be0a78 | 44 | /** Possible owners of http header */ |
25b6a907 | 45 | typedef enum { |
0b57cb3d | 46 | hoNone =0, |
25b6a907 | 47 | #if USE_HTCP |
48 | hoHtcpReply, | |
49 | #endif | |
50 | hoRequest, | |
02259ff8 | 51 | hoReply, |
cb4f4424 | 52 | #if USE_OPENSSL |
02259ff8 CT |
53 | hoErrorDetail, |
54 | #endif | |
55 | hoEnd | |
25b6a907 | 56 | } http_hdr_owner_type; |
57 | ||
1b2f0924 FC |
58 | class HttpHeaderFieldAttrs |
59 | { | |
09bbee4c | 60 | public: |
26735116 AJ |
61 | HttpHeaderFieldAttrs() : name(NULL), id(HDR_BAD_HDR), type(ftInvalid) {} |
62 | HttpHeaderFieldAttrs(const char *aName, http_hdr_type anId, field_type aType = ftInvalid) : name(aName), id(anId), type(aType) {} | |
63 | #if __cplusplus >= 201103L | |
64 | HttpHeaderFieldAttrs(const HttpHeaderFieldAttrs &) = default; | |
65 | HttpHeaderFieldAttrs(HttpHeaderFieldAttrs &&) = default; | |
66 | #endif | |
67 | // nothing to do as name is a pointer to global const string | |
68 | ~HttpHeaderFieldAttrs() {} | |
69 | ||
e6ccf245 | 70 | const char *name; |
71 | http_hdr_type id; | |
72 | field_type type; | |
73 | }; | |
74 | ||
63be0a78 | 75 | /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */ |
985c86bc | 76 | typedef ssize_t HttpHeaderPos; |
77 | ||
78 | /* use this and only this to initialize HttpHeaderPos */ | |
79 | #define HttpHeaderInitPos (-1) | |
80 | ||
eede25e7 | 81 | class HttpHeaderEntry |
82 | { | |
741c2986 | 83 | MEMPROXY_CLASS(HttpHeaderEntry); |
eede25e7 | 84 | |
85 | public: | |
eede25e7 | 86 | HttpHeaderEntry(http_hdr_type id, const char *name, const char *value); |
87 | ~HttpHeaderEntry(); | |
cdce6c61 | 88 | static HttpHeaderEntry *parse(const char *field_start, const char *field_end); |
eede25e7 | 89 | HttpHeaderEntry *clone() const; |
90 | void packInto(Packer *p) const; | |
91 | int getInt() const; | |
47f6e231 | 92 | int64_t getInt64() const; |
741c2986 | 93 | |
eede25e7 | 94 | http_hdr_type id; |
30abd221 | 95 | String name; |
96 | String value; | |
eede25e7 | 97 | }; |
98 | ||
81a94152 AJ |
99 | class ETag; |
100 | class TimeOrTag; | |
101 | ||
924f73bc | 102 | class HttpHeader |
103 | { | |
104 | ||
105 | public: | |
75faaa7a | 106 | HttpHeader(); |
5e5fa5b1 AR |
107 | explicit HttpHeader(const http_hdr_owner_type owner); |
108 | HttpHeader(const HttpHeader &other); | |
75faaa7a | 109 | ~HttpHeader(); |
5e5fa5b1 AR |
110 | |
111 | HttpHeader &operator =(const HttpHeader &other); | |
112 | ||
924f73bc | 113 | /* Interface functions */ |
519e0948 | 114 | void clean(); |
a9925b40 | 115 | void append(const HttpHeader * src); |
116 | void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask); | |
394499bd | 117 | void compact(); |
a9925b40 | 118 | int reset(); |
784619e6 | 119 | int parse(const char *header_start, size_t len); |
d8f6c79c | 120 | void packInto(Packer * p, bool mask_sensitive_info=false) const; |
a9925b40 | 121 | HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const; |
122 | HttpHeaderEntry *findEntry(http_hdr_type id) const; | |
123 | int delByName(const char *name); | |
124 | int delById(http_hdr_type id); | |
ba9fb01d | 125 | void delAt(HttpHeaderPos pos, int &headers_deleted); |
126 | void refreshMask(); | |
a9925b40 | 127 | void addEntry(HttpHeaderEntry * e); |
128 | void insertEntry(HttpHeaderEntry * e); | |
30abd221 | 129 | String getList(http_hdr_type id) const; |
130 | bool getList(http_hdr_type id, String *s) const; | |
131 | String getStrOrList(http_hdr_type id) const; | |
132 | String getByName(const char *name) const; | |
b2c44718 AR |
133 | /// sets value and returns true iff a [possibly empty] named field is there |
134 | bool getByNameIfPresent(const char *name, String &value) const; | |
30abd221 | 135 | String getByNameListMember(const char *name, const char *member, const char separator) const; |
136 | String getListMember(http_hdr_type id, const char *member, const char separator) const; | |
a9925b40 | 137 | int has(http_hdr_type id) const; |
138 | void putInt(http_hdr_type id, int number); | |
47f6e231 | 139 | void putInt64(http_hdr_type id, int64_t number); |
a9925b40 | 140 | void putTime(http_hdr_type id, time_t htime); |
141 | void insertTime(http_hdr_type id, time_t htime); | |
142 | void putStr(http_hdr_type id, const char *str); | |
143 | void putAuth(const char *auth_scheme, const char *realm); | |
144 | void putCc(const HttpHdrCc * cc); | |
145 | void putContRange(const HttpHdrContRange * cr); | |
146 | void putRange(const HttpHdrRange * range); | |
147 | void putSc(HttpHdrSc *sc); | |
bcfba8bd | 148 | void putWarning(const int code, const char *const text); ///< add a Warning header |
a9925b40 | 149 | void putExt(const char *name, const char *value); |
150 | int getInt(http_hdr_type id) const; | |
47f6e231 | 151 | int64_t getInt64(http_hdr_type id) const; |
a9925b40 | 152 | time_t getTime(http_hdr_type id) const; |
153 | const char *getStr(http_hdr_type id) const; | |
154 | const char *getLastStr(http_hdr_type id) const; | |
155 | HttpHdrCc *getCc() const; | |
156 | HttpHdrRange *getRange() const; | |
157 | HttpHdrSc *getSc() const; | |
158 | HttpHdrContRange *getContRange() const; | |
159 | const char *getAuth(http_hdr_type id, const char *auth_scheme) const; | |
160 | ETag getETag(http_hdr_type id) const; | |
161 | TimeOrTag getTimeOrTag(http_hdr_type id) const; | |
162 | int hasListMember(http_hdr_type id, const char *member, const char separator) const; | |
163 | int hasByNameListMember(const char *name, const char *member, const char separator) const; | |
2cdeea82 | 164 | void removeHopByHopEntries(); |
c3d0ba0c | 165 | inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding |
63be0a78 | 166 | |
924f73bc | 167 | /* protected, do not use these, use interface functions instead */ |
f53969cc SM |
168 | std::vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */ |
169 | HttpHeaderMask mask; /**< bit set <=> entry present */ | |
170 | http_hdr_owner_type owner; /**< request or reply */ | |
171 | int len; /**< length when packed, not counting terminating null-byte */ | |
a9925b40 | 172 | |
2cdeea82 | 173 | protected: |
63be0a78 | 174 | /** \deprecated Public access replaced by removeHopByHopEntries() */ |
2cdeea82 | 175 | void removeConnectionHeaderEntries(); |
63be0a78 | 176 | |
a9925b40 | 177 | private: |
178 | HttpHeaderEntry *findLastEntry(http_hdr_type id) const; | |
924f73bc | 179 | }; |
528b2c61 | 180 | |
8a648e8d | 181 | int httpHeaderParseQuotedString(const char *start, const int len, String *val); |
a2c7f09a | 182 | |
e7ce227f AR |
183 | /// quotes string using RFC 7230 quoted-string rules |
184 | SBuf httpHeaderQuoteString(const char *raw); | |
a2c7f09a | 185 | |
8a648e8d FC |
186 | int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator); |
187 | void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask); | |
188 | void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count); | |
25b6a907 | 189 | |
c3d0ba0c AR |
190 | inline bool |
191 | HttpHeader::chunked() const | |
192 | { | |
193 | return has(HDR_TRANSFER_ENCODING) && | |
f673997d | 194 | hasListMember(HDR_TRANSFER_ENCODING, "chunked", ','); |
c3d0ba0c AR |
195 | } |
196 | ||
8a648e8d FC |
197 | void httpHeaderInitModule(void); |
198 | void httpHeaderCleanModule(void); | |
ec6f82c1 | 199 | |
e6ccf245 | 200 | #endif /* SQUID_HTTPHEADER_H */ |
f53969cc | 201 |