]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeader.h
Renamed http_hdr_type to Http::HdrType, fixed some HdrType-int implicit conversions
[thirdparty/squid.git] / src / HttpHeader.h
CommitLineData
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 22class HttpHdrCc;
71b673d4 23class HttpHdrContRange;
696a257c 24class HttpHdrRange;
71b673d4 25class HttpHdrSc;
17802cf1 26class Packable;
e7ce227f 27class SBuf;
696a257c 28
63be0a78 29/** Possible owners of http header */
25b6a907 30typedef 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 44typedef ssize_t HttpHeaderPos;
45
46/* use this and only this to initialize HttpHeaderPos */
47#define HttpHeaderInitPos (-1)
48
eede25e7 49class HttpHeaderEntry
50{
741c2986 51 MEMPROXY_CLASS(HttpHeaderEntry);
eede25e7 52
53public:
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
67class ETag;
68class TimeOrTag;
69
924f73bc 70class HttpHeader
71{
72
73public:
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;
99 String getStrOrList(Http::HdrType id) const;
30abd221 100 String getByName(const char *name) const;
b2c44718
AR
101 /// sets value and returns true iff a [possibly empty] named field is there
102 bool getByNameIfPresent(const char *name, String &value) const;
30abd221 103 String getByNameListMember(const char *name, const char *member, const char separator) const;
789217a2
FC
104 String getListMember(Http::HdrType id, const char *member, const char separator) const;
105 int has(Http::HdrType id) const;
106 void putInt(Http::HdrType id, int number);
107 void putInt64(Http::HdrType id, int64_t number);
108 void putTime(Http::HdrType id, time_t htime);
109 void insertTime(Http::HdrType id, time_t htime);
110 void putStr(Http::HdrType id, const char *str);
a9925b40 111 void putAuth(const char *auth_scheme, const char *realm);
112 void putCc(const HttpHdrCc * cc);
113 void putContRange(const HttpHdrContRange * cr);
114 void putRange(const HttpHdrRange * range);
115 void putSc(HttpHdrSc *sc);
bcfba8bd 116 void putWarning(const int code, const char *const text); ///< add a Warning header
a9925b40 117 void putExt(const char *name, const char *value);
789217a2
FC
118 int getInt(Http::HdrType id) const;
119 int64_t getInt64(Http::HdrType id) const;
120 time_t getTime(Http::HdrType id) const;
121 const char *getStr(Http::HdrType id) const;
122 const char *getLastStr(Http::HdrType id) const;
a9925b40 123 HttpHdrCc *getCc() const;
124 HttpHdrRange *getRange() const;
125 HttpHdrSc *getSc() const;
126 HttpHdrContRange *getContRange() const;
789217a2
FC
127 const char *getAuth(Http::HdrType id, const char *auth_scheme) const;
128 ETag getETag(Http::HdrType id) const;
129 TimeOrTag getTimeOrTag(Http::HdrType id) const;
130 int hasListMember(Http::HdrType id, const char *member, const char separator) const;
a9925b40 131 int hasByNameListMember(const char *name, const char *member, const char separator) const;
2cdeea82 132 void removeHopByHopEntries();
c3d0ba0c 133 inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding
63be0a78 134
924f73bc 135 /* protected, do not use these, use interface functions instead */
f53969cc
SM
136 std::vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */
137 HttpHeaderMask mask; /**< bit set <=> entry present */
138 http_hdr_owner_type owner; /**< request or reply */
139 int len; /**< length when packed, not counting terminating null-byte */
a9925b40 140
2cdeea82 141protected:
63be0a78 142 /** \deprecated Public access replaced by removeHopByHopEntries() */
2cdeea82 143 void removeConnectionHeaderEntries();
63be0a78 144
a9925b40 145private:
789217a2 146 HttpHeaderEntry *findLastEntry(Http::HdrType id) const;
924f73bc 147};
528b2c61 148
8a648e8d 149int httpHeaderParseQuotedString(const char *start, const int len, String *val);
a2c7f09a 150
e7ce227f
AR
151/// quotes string using RFC 7230 quoted-string rules
152SBuf httpHeaderQuoteString(const char *raw);
a2c7f09a 153
8a648e8d
FC
154int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
155void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
789217a2 156void httpHeaderCalcMask(HttpHeaderMask * mask, Http::HdrType http_hdr_type_enums[], size_t count);
25b6a907 157
c3d0ba0c
AR
158inline bool
159HttpHeader::chunked() const
160{
789217a2
FC
161 return has(Http::HdrType::TRANSFER_ENCODING) &&
162 hasListMember(Http::HdrType::TRANSFER_ENCODING, "chunked", ',');
c3d0ba0c
AR
163}
164
8a648e8d
FC
165void httpHeaderInitModule(void);
166void httpHeaderCleanModule(void);
ec6f82c1 167
e6ccf245 168#endif /* SQUID_HTTPHEADER_H */
f53969cc 169