]>
Commit | Line | Data |
---|---|---|
e6ccf245 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 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(); |
784619e6 | 86 | int parse(const char *header_start, size_t len); |
17802cf1 | 87 | void packInto(Packable * p, bool mask_sensitive_info=false) const; |
a9925b40 | 88 | HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const; |
789217a2 | 89 | HttpHeaderEntry *findEntry(Http::HdrType id) const; |
a9925b40 | 90 | int delByName(const char *name); |
789217a2 | 91 | int delById(Http::HdrType id); |
ba9fb01d | 92 | void delAt(HttpHeaderPos pos, int &headers_deleted); |
93 | void refreshMask(); | |
a9925b40 | 94 | void addEntry(HttpHeaderEntry * e); |
95 | void insertEntry(HttpHeaderEntry * e); | |
789217a2 FC |
96 | String getList(Http::HdrType id) const; |
97 | bool getList(Http::HdrType id, String *s) const; | |
3e42b356 | 98 | bool conflictingContentLength() const { return conflictingContentLength_; } |
789217a2 | 99 | String getStrOrList(Http::HdrType id) const; |
81ab22b6 | 100 | String getByName(const SBuf &name) const; |
30abd221 | 101 | String getByName(const char *name) const; |
81ab22b6 FC |
102 | String getById(Http::HdrType id) const; |
103 | /// sets value and returns true iff a [possibly empty] field identified by id is there | |
104 | bool getByIdIfPresent(Http::HdrType id, String &result) const; | |
b2c44718 | 105 | /// sets value and returns true iff a [possibly empty] named field is there |
81ab22b6 FC |
106 | bool getByNameIfPresent(const SBuf &s, String &value) const; |
107 | bool getByNameIfPresent(const char *name, int namelen, String &value) const; | |
30abd221 | 108 | String getByNameListMember(const char *name, const char *member, const char separator) const; |
789217a2 FC |
109 | String getListMember(Http::HdrType id, const char *member, const char separator) const; |
110 | int has(Http::HdrType id) const; | |
111 | void putInt(Http::HdrType id, int number); | |
112 | void putInt64(Http::HdrType id, int64_t number); | |
113 | void putTime(Http::HdrType id, time_t htime); | |
789217a2 | 114 | void putStr(Http::HdrType id, const char *str); |
a9925b40 | 115 | void putAuth(const char *auth_scheme, const char *realm); |
116 | void putCc(const HttpHdrCc * cc); | |
117 | void putContRange(const HttpHdrContRange * cr); | |
118 | void putRange(const HttpHdrRange * range); | |
119 | void putSc(HttpHdrSc *sc); | |
bcfba8bd | 120 | void putWarning(const int code, const char *const text); ///< add a Warning header |
a9925b40 | 121 | void putExt(const char *name, const char *value); |
789217a2 FC |
122 | int getInt(Http::HdrType id) const; |
123 | int64_t getInt64(Http::HdrType id) const; | |
124 | time_t getTime(Http::HdrType id) const; | |
125 | const char *getStr(Http::HdrType id) const; | |
126 | const char *getLastStr(Http::HdrType id) const; | |
a9925b40 | 127 | HttpHdrCc *getCc() const; |
128 | HttpHdrRange *getRange() const; | |
129 | HttpHdrSc *getSc() const; | |
130 | HttpHdrContRange *getContRange() const; | |
789217a2 FC |
131 | const char *getAuth(Http::HdrType id, const char *auth_scheme) const; |
132 | ETag getETag(Http::HdrType id) const; | |
133 | TimeOrTag getTimeOrTag(Http::HdrType id) const; | |
134 | int hasListMember(Http::HdrType id, const char *member, const char separator) const; | |
a9925b40 | 135 | int hasByNameListMember(const char *name, const char *member, const char separator) const; |
2cdeea82 | 136 | void removeHopByHopEntries(); |
c3d0ba0c | 137 | inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding |
63be0a78 | 138 | |
924f73bc | 139 | /* protected, do not use these, use interface functions instead */ |
f53969cc SM |
140 | std::vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */ |
141 | HttpHeaderMask mask; /**< bit set <=> entry present */ | |
142 | http_hdr_owner_type owner; /**< request or reply */ | |
143 | int len; /**< length when packed, not counting terminating null-byte */ | |
a9925b40 | 144 | |
2cdeea82 | 145 | protected: |
63be0a78 | 146 | /** \deprecated Public access replaced by removeHopByHopEntries() */ |
2cdeea82 | 147 | void removeConnectionHeaderEntries(); |
63be0a78 | 148 | |
a9925b40 | 149 | private: |
789217a2 | 150 | HttpHeaderEntry *findLastEntry(Http::HdrType id) const; |
3e42b356 | 151 | bool conflictingContentLength_; ///< found different Content-Length fields |
924f73bc | 152 | }; |
528b2c61 | 153 | |
8a648e8d | 154 | int httpHeaderParseQuotedString(const char *start, const int len, String *val); |
a2c7f09a | 155 | |
e7ce227f AR |
156 | /// quotes string using RFC 7230 quoted-string rules |
157 | SBuf httpHeaderQuoteString(const char *raw); | |
a2c7f09a | 158 | |
789217a2 | 159 | void httpHeaderCalcMask(HttpHeaderMask * mask, Http::HdrType http_hdr_type_enums[], size_t count); |
25b6a907 | 160 | |
c3d0ba0c AR |
161 | inline bool |
162 | HttpHeader::chunked() const | |
163 | { | |
789217a2 FC |
164 | return has(Http::HdrType::TRANSFER_ENCODING) && |
165 | hasListMember(Http::HdrType::TRANSFER_ENCODING, "chunked", ','); | |
c3d0ba0c AR |
166 | } |
167 | ||
8a648e8d | 168 | void httpHeaderInitModule(void); |
ec6f82c1 | 169 | |
e6ccf245 | 170 | #endif /* SQUID_HTTPHEADER_H */ |
f53969cc | 171 |