2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_HTTPHEADER_H
10 #define SQUID_HTTPHEADER_H
12 #include "base/LookupTable.h"
13 #include "http/RegisteredHeaders.h"
14 /* because we pass a spec by value */
15 #include "HttpHeaderMask.h"
16 #include "mem/forward.h"
17 #include "SquidString.h"
21 /* class forward declarations */
23 class HttpHdrContRange
;
29 /** Possible owners of http header */
41 } http_hdr_owner_type
;
43 /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
44 typedef ssize_t HttpHeaderPos
;
46 /* use this and only this to initialize HttpHeaderPos */
47 #define HttpHeaderInitPos (-1)
51 MEMPROXY_CLASS(HttpHeaderEntry
);
54 HttpHeaderEntry(http_hdr_type id
, const char *name
, const char *value
);
56 static HttpHeaderEntry
*parse(const char *field_start
, const char *field_end
);
57 HttpHeaderEntry
*clone() const;
58 void packInto(Packable
*p
) const;
60 int64_t getInt64() const;
75 explicit HttpHeader(const http_hdr_owner_type owner
);
76 HttpHeader(const HttpHeader
&other
);
79 HttpHeader
&operator =(const HttpHeader
&other
);
81 /* Interface functions */
83 void append(const HttpHeader
* src
);
84 void update (HttpHeader
const *fresh
, HttpHeaderMask
const *denied_mask
);
87 int parse(const char *header_start
, size_t len
);
88 void packInto(Packable
* p
, bool mask_sensitive_info
=false) const;
89 HttpHeaderEntry
*getEntry(HttpHeaderPos
* pos
) const;
90 HttpHeaderEntry
*findEntry(http_hdr_type id
) const;
91 int delByName(const char *name
);
92 int delById(http_hdr_type id
);
93 void delAt(HttpHeaderPos pos
, int &headers_deleted
);
95 void addEntry(HttpHeaderEntry
* e
);
96 void insertEntry(HttpHeaderEntry
* e
);
97 String
getList(http_hdr_type id
) const;
98 bool getList(http_hdr_type id
, String
*s
) const;
99 String
getStrOrList(http_hdr_type id
) const;
100 String
getByName(const char *name
) const;
101 /// sets value and returns true iff a [possibly empty] named field is there
102 bool getByNameIfPresent(const char *name
, String
&value
) const;
103 String
getByNameListMember(const char *name
, const char *member
, const char separator
) const;
104 String
getListMember(http_hdr_type id
, const char *member
, const char separator
) const;
105 int has(http_hdr_type id
) const;
106 void putInt(http_hdr_type id
, int number
);
107 void putInt64(http_hdr_type id
, int64_t number
);
108 void putTime(http_hdr_type id
, time_t htime
);
109 void insertTime(http_hdr_type id
, time_t htime
);
110 void putStr(http_hdr_type id
, const char *str
);
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
);
116 void putWarning(const int code
, const char *const text
); ///< add a Warning header
117 void putExt(const char *name
, const char *value
);
118 int getInt(http_hdr_type id
) const;
119 int64_t getInt64(http_hdr_type id
) const;
120 time_t getTime(http_hdr_type id
) const;
121 const char *getStr(http_hdr_type id
) const;
122 const char *getLastStr(http_hdr_type id
) const;
123 HttpHdrCc
*getCc() const;
124 HttpHdrRange
*getRange() const;
125 HttpHdrSc
*getSc() const;
126 HttpHdrContRange
*getContRange() const;
127 const char *getAuth(http_hdr_type id
, const char *auth_scheme
) const;
128 ETag
getETag(http_hdr_type id
) const;
129 TimeOrTag
getTimeOrTag(http_hdr_type id
) const;
130 int hasListMember(http_hdr_type id
, const char *member
, const char separator
) const;
131 int hasByNameListMember(const char *name
, const char *member
, const char separator
) const;
132 void removeHopByHopEntries();
133 inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding
135 /* protected, do not use these, use interface functions instead */
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 */
142 /** \deprecated Public access replaced by removeHopByHopEntries() */
143 void removeConnectionHeaderEntries();
146 HttpHeaderEntry
*findLastEntry(http_hdr_type id
) const;
149 int httpHeaderParseQuotedString(const char *start
, const int len
, String
*val
);
151 /// quotes string using RFC 7230 quoted-string rules
152 SBuf
httpHeaderQuoteString(const char *raw
);
154 int httpHeaderHasByNameListMember(const HttpHeader
* hdr
, const char *name
, const char *member
, const char separator
);
155 void httpHeaderUpdate(HttpHeader
* old
, const HttpHeader
* fresh
, const HttpHeaderMask
* denied_mask
);
156 void httpHeaderCalcMask(HttpHeaderMask
* mask
, http_hdr_type http_hdr_type_enums
[], size_t count
);
159 HttpHeader::chunked() const
161 return has(HDR_TRANSFER_ENCODING
) &&
162 hasListMember(HDR_TRANSFER_ENCODING
, "chunked", ',');
165 void httpHeaderInitModule(void);
166 void httpHeaderCleanModule(void);
168 // for header string->id lookup, use headerLookupTable.lookup(hdr-as-sbuf);
169 extern const LookupTable
<http_hdr_type
, HeaderTableRecord
> headerLookupTable
;
171 #endif /* SQUID_HTTPHEADER_H */