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