Squid Web Cache
master
Loading...
Searching...
No Matches
HttpHeader.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3
*
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.
7
*/
8
9
#ifndef SQUID_SRC_HTTPHEADER_H
10
#define SQUID_SRC_HTTPHEADER_H
11
12
#include "
anyp/ProtocolVersion.h
"
13
#include "
base/LookupTable.h
"
14
#include "
http/RegisteredHeaders.h
"
15
/* because we pass a spec by value */
16
#include "
HttpHeaderMask.h
"
17
#include "
mem/PoolingAllocator.h
"
18
#include "
sbuf/forward.h
"
19
#include "
SquidString.h
"
20
21
#include <vector>
22
23
/* class forward declarations */
24
class
HttpHdrCc
;
25
class
HttpHdrContRange
;
26
class
HttpHdrRange
;
27
class
HttpHdrSc
;
28
class
Packable
;
29
31
typedef
enum
{
32
hoNone
=0,
33
#if USE_HTCP
34
hoHtcpReply
,
35
#endif
36
hoRequest
,
37
hoReply
,
38
#if USE_OPENSSL
39
hoErrorDetail
,
40
#endif
41
hoEnd
42
}
http_hdr_owner_type
;
43
45
typedef
ssize_t
HttpHeaderPos
;
46
47
/* use this and only this to initialize HttpHeaderPos */
48
#define HttpHeaderInitPos (-1)
49
50
class
HttpHeaderEntry
51
{
52
MEMPROXY_CLASS
(
HttpHeaderEntry
);
53
54
public
:
55
HttpHeaderEntry
(
Http::HdrType
id
,
const
SBuf
&
name
,
const
char
*
value
);
56
~HttpHeaderEntry
();
57
static
HttpHeaderEntry
*
parse
(
const
char
*field_start,
const
char
*field_end,
const
http_hdr_owner_type
msgType);
58
HttpHeaderEntry
*
clone
()
const
;
59
void
packInto
(
Packable
*p)
const
;
60
int
getInt
()
const
;
61
int64_t
getInt64
()
const
;
62
64
size_t
length
()
const
{
return
name
.
length
() + 2 +
value
.
size
() + 2; }
65
66
Http::HdrType
id
;
67
SBuf
name
;
68
String
value
;
69
};
70
71
class
ETag
;
72
class
TimeOrTag
;
73
74
class
HttpHeader
75
{
76
77
public
:
78
explicit
HttpHeader
(
const
http_hdr_owner_type
owner
);
79
HttpHeader
(
const
HttpHeader
&other);
80
~HttpHeader
();
81
82
HttpHeader
&
operator =
(
const
HttpHeader
&other);
83
84
/* Interface functions */
85
void
clean
();
86
void
append
(
const
HttpHeader
* src);
89
void
update
(
const
HttpHeader
*fresh);
91
bool
needUpdate
(
const
HttpHeader
*fresh)
const
;
92
void
compact
();
93
int
parse
(
const
char
*header_start,
size_t
len
,
Http::ContentLengthInterpreter
&interpreter);
98
int
parse
(
const
char
*buf,
size_t
buf_len,
bool
atEnd,
size_t
&hdr_sz,
Http::ContentLengthInterpreter
&interpreter);
99
void
packInto
(
Packable
* p,
bool
mask_sensitive_info=
false
)
const
;
100
HttpHeaderEntry
*
getEntry
(
HttpHeaderPos
* pos)
const
;
101
HttpHeaderEntry
*
findEntry
(
Http::HdrType
id
)
const
;
104
int
delByName
(
const
SBuf
&name);
106
int
delByName
(
const
char
*name) {
return
delByName
(
SBuf
(name)); }
107
int
delById
(
Http::HdrType
id
);
108
void
delAt
(
HttpHeaderPos
pos,
int
&headers_deleted);
109
void
refreshMask
();
110
void
addEntry
(
HttpHeaderEntry
* e);
111
String
getList
(
Http::HdrType
id
)
const
;
112
bool
getList
(
Http::HdrType
id
,
String
*s)
const
;
113
bool
conflictingContentLength
()
const
{
return
conflictingContentLength_
; }
114
String
getStrOrList
(
Http::HdrType
id
)
const
;
115
String
getByName
(
const
SBuf
&name)
const
;
116
String
getByName
(
const
char
*name)
const
;
117
String
getById
(
Http::HdrType
id
)
const
;
120
bool
getByIdIfPresent
(
Http::HdrType
id
,
String
*result)
const
;
123
bool
hasNamed
(
const
SBuf
&s,
String
*value =
nullptr
)
const
;
125
bool
hasNamed
(
const
char
*name,
unsigned
int
namelen,
String
*value =
nullptr
)
const
;
128
SBuf
getByNameListMember
(
const
char
*name,
const
char
*member,
const
char
separator)
const
;
131
SBuf
getListMember
(
Http::HdrType
id
,
const
char
*member,
const
char
separator)
const
;
132
int
has
(
Http::HdrType
id
)
const
;
135
void
addVia
(
const
AnyP::ProtocolVersion
&ver,
const
HttpHeader
*from =
nullptr
);
136
void
putInt
(
Http::HdrType
id
,
int
number
);
137
void
putInt64
(
Http::HdrType
id
, int64_t
number
);
138
void
putTime
(
Http::HdrType
id
, time_t htime);
139
void
putStr
(
Http::HdrType
id
,
const
char
*str);
140
void
putAuth
(
const
char
*auth_scheme,
const
char
*realm);
141
void
putCc
(
const
HttpHdrCc
&cc);
142
void
putContRange
(
const
HttpHdrContRange
* cr);
143
void
putRange
(
const
HttpHdrRange
* range);
144
void
putSc
(
HttpHdrSc
*sc);
145
void
putExt
(
const
char
*name,
const
char
*value);
146
149
void
updateOrAddStr
(
Http::HdrType
,
const
SBuf
&);
150
151
int
getInt
(
Http::HdrType
id
)
const
;
152
int64_t
getInt64
(
Http::HdrType
id
)
const
;
153
time_t
getTime
(
Http::HdrType
id
)
const
;
154
const
char
*
getStr
(
Http::HdrType
id
)
const
;
155
const
char
*
getLastStr
(
Http::HdrType
id
)
const
;
156
HttpHdrCc
*
getCc
()
const
;
157
HttpHdrRange
*
getRange
()
const
;
158
HttpHdrSc
*
getSc
()
const
;
159
HttpHdrContRange
*
getContRange
()
const
;
160
SBuf
getAuthToken
(
Http::HdrType
id
,
const
char
*auth_scheme)
const
;
161
ETag
getETag
(
Http::HdrType
id
)
const
;
162
TimeOrTag
getTimeOrTag
(
Http::HdrType
id
)
const
;
163
int
hasListMember
(
Http::HdrType
id
,
const
char
*member,
const
char
separator)
const
;
164
int
hasByNameListMember
(
const
char
*name,
const
char
*member,
const
char
separator)
const
;
165
void
removeHopByHopEntries
();
166
169
bool
chunked
()
const
{
return
has
(
Http::HdrType::TRANSFER_ENCODING
); }
170
172
bool
unsupportedTe
()
const
{
return
teUnsupported_
; }
173
174
/* protected, do not use these, use interface functions instead */
175
std::vector<HttpHeaderEntry*, PoolingAllocator<HttpHeaderEntry*> >
entries
;
176
HttpHeaderMask
mask
;
177
http_hdr_owner_type
owner
;
178
int
len
;
180
protected
:
182
void
removeConnectionHeaderEntries
();
189
static
bool
Isolate
(
const
char
**parse_start,
size_t
l,
const
char
**blk_start,
const
char
**blk_end);
190
bool
skipUpdateHeader
(
const
Http::HdrType
id
)
const
;
191
192
private
:
193
HttpHeaderEntry
*
findLastEntry
(
Http::HdrType
id
)
const
;
194
bool
conflictingContentLength_
;
197
bool
teUnsupported_
=
false
;
198
};
199
200
int
httpHeaderParseQuotedString
(
const
char
*start,
const
int
len,
String
*val);
201
202
namespace
Http
{
203
218
SBuf
SlowlyParseQuotedString
(
const
char
*description,
const
char
*start,
size_t
length);
219
220
}
221
223
SBuf
httpHeaderQuoteString
(
const
char
*raw);
224
225
void
httpHeaderCalcMask
(
HttpHeaderMask
* mask,
Http::HdrType
http_hdr_type_enums[],
size_t
count);
226
227
void
httpHeaderInitModule
(
void
);
228
229
#endif
/* SQUID_SRC_HTTPHEADER_H */
230
HttpHeaderMask.h
HttpHeaderMask
char HttpHeaderMask[12]
Definition
HttpHeaderMask.h:13
httpHeaderQuoteString
SBuf httpHeaderQuoteString(const char *raw)
quotes string using RFC 7230 quoted-string rules
Definition
HttpHeader.cc:237
http_hdr_owner_type
http_hdr_owner_type
Definition
HttpHeader.h:31
hoRequest
@ hoRequest
Definition
HttpHeader.h:36
hoNone
@ hoNone
Definition
HttpHeader.h:32
hoReply
@ hoReply
Definition
HttpHeader.h:37
hoHtcpReply
@ hoHtcpReply
Definition
HttpHeader.h:34
hoEnd
@ hoEnd
Definition
HttpHeader.h:41
hoErrorDetail
@ hoErrorDetail
Definition
HttpHeader.h:39
httpHeaderCalcMask
void httpHeaderCalcMask(HttpHeaderMask *mask, Http::HdrType http_hdr_type_enums[], size_t count)
HttpHeaderPos
ssize_t HttpHeaderPos
Definition
HttpHeader.h:45
httpHeaderParseQuotedString
int httpHeaderParseQuotedString(const char *start, const int len, String *val)
Definition
HttpHeader.cc:167
httpHeaderInitModule
void httpHeaderInitModule(void)
Definition
HttpHeader.cc:138
LookupTable.h
PoolingAllocator.h
RegisteredHeaders.h
SquidString.h
ProtocolVersion.h
AnyP::ProtocolVersion
Definition
ProtocolVersion.h:24
ETag
Definition
ETag.h:18
HttpHdrCc
Definition
HttpHdrCc.h:44
HttpHdrContRange
Definition
HttpHdrContRange.h:18
HttpHdrRange
Definition
HttpHeaderRange.h:52
HttpHdrSc
Definition
HttpHdrSc.h:25
HttpHeaderEntry
Definition
HttpHeader.h:51
HttpHeaderEntry::packInto
void packInto(Packable *p) const
Definition
HttpHeader.cc:1645
HttpHeaderEntry::parse
static HttpHeaderEntry * parse(const char *field_start, const char *field_end, const http_hdr_owner_type msgType)
Definition
HttpHeader.cc:1525
HttpHeaderEntry::getInt
int getInt() const
Definition
HttpHeader.cc:1655
HttpHeaderEntry::clone
HttpHeaderEntry * clone() const
Definition
HttpHeader.cc:1639
HttpHeaderEntry::MEMPROXY_CLASS
MEMPROXY_CLASS(HttpHeaderEntry)
HttpHeaderEntry::length
size_t length() const
expected number of bytes written by packInto(), including ": " and CRLF
Definition
HttpHeader.h:64
HttpHeaderEntry::getInt64
int64_t getInt64() const
Definition
HttpHeader.cc:1667
HttpHeaderEntry::id
Http::HdrType id
Definition
HttpHeader.h:66
HttpHeaderEntry::~HttpHeaderEntry
~HttpHeaderEntry()
Definition
HttpHeader.cc:1511
HttpHeaderEntry::value
String value
Definition
HttpHeader.h:68
HttpHeaderEntry::name
SBuf name
Definition
HttpHeader.h:67
HttpHeader
Definition
HttpHeader.h:75
HttpHeader::getByNameListMember
SBuf getByNameListMember(const char *name, const char *member, const char separator) const
Definition
HttpHeader.cc:1050
HttpHeader::removeHopByHopEntries
void removeHopByHopEntries()
Definition
HttpHeader.cc:1843
HttpHeader::putStr
void putStr(Http::HdrType id, const char *str)
Definition
HttpHeader.cc:1128
HttpHeader::getTimeOrTag
TimeOrTag getTimeOrTag(Http::HdrType id) const
Definition
HttpHeader.cc:1463
HttpHeader::getCc
HttpHdrCc * getCc() const
Definition
HttpHeader.cc:1327
HttpHeader::getByIdIfPresent
bool getByIdIfPresent(Http::HdrType id, String *result) const
Definition
HttpHeader.cc:1004
HttpHeader::hasByNameListMember
int hasByNameListMember(const char *name, const char *member, const char separator) const
Definition
HttpHeader.cc:1819
HttpHeader::chunked
bool chunked() const
Definition
HttpHeader.h:169
HttpHeader::delAt
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition
HttpHeader.cc:827
HttpHeader::unsupportedTe
bool unsupportedTe() const
whether message used an unsupported and/or invalid Transfer-Encoding
Definition
HttpHeader.h:172
HttpHeader::parse
int parse(const char *header_start, size_t len, Http::ContentLengthInterpreter &interpreter)
Definition
HttpHeader.cc:482
HttpHeader::getListMember
SBuf getListMember(Http::HdrType id, const char *member, const char separator) const
Definition
HttpHeader.cc:1061
HttpHeader::putCc
void putCc(const HttpHdrCc &cc)
Definition
HttpHeader.cc:1144
HttpHeader::getStrOrList
String getStrOrList(Http::HdrType id) const
Definition
HttpHeader.cc:955
HttpHeader::getETag
ETag getETag(Http::HdrType id) const
Definition
HttpHeader.cc:1450
HttpHeader::putInt
void putInt(Http::HdrType id, int number)
Definition
HttpHeader.cc:1101
HttpHeader::compact
void compact()
Definition
HttpHeader.cc:844
HttpHeader::owner
http_hdr_owner_type owner
Definition
HttpHeader.h:177
HttpHeader::delById
int delById(Http::HdrType id)
Definition
HttpHeader.cc:799
HttpHeader::getList
String getList(Http::HdrType id) const
Definition
HttpHeader.cc:921
HttpHeader::conflictingContentLength_
bool conflictingContentLength_
Definition
HttpHeader.h:194
HttpHeader::putContRange
void putContRange(const HttpHdrContRange *cr)
Definition
HttpHeader.cc:1159
HttpHeader::refreshMask
void refreshMask()
Definition
HttpHeader.cc:855
HttpHeader::update
void update(const HttpHeader *fresh)
Definition
HttpHeader.cc:400
HttpHeader::getAuthToken
SBuf getAuthToken(Http::HdrType id, const char *auth_scheme) const
Definition
HttpHeader.cc:1408
HttpHeader::getEntry
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition
HttpHeader.cc:716
HttpHeader::Isolate
static bool Isolate(const char **parse_start, size_t l, const char **blk_start, const char **blk_end)
Definition
HttpHeader.cc:434
HttpHeader::getStr
const char * getStr(Http::HdrType id) const
Definition
HttpHeader.cc:1296
HttpHeader::delByName
int delByName(const char *name)
Definition
HttpHeader.h:106
HttpHeader::entries
std::vector< HttpHeaderEntry *, PoolingAllocator< HttpHeaderEntry * > > entries
Definition
HttpHeader.h:175
HttpHeader::operator=
HttpHeader & operator=(const HttpHeader &other)
Definition
HttpHeader.cc:303
HttpHeader::~HttpHeader
~HttpHeader()
Definition
HttpHeader.cc:296
HttpHeader::putSc
void putSc(HttpHdrSc *sc)
Definition
HttpHeader.cc:1191
HttpHeader::teUnsupported_
bool teUnsupported_
Definition
HttpHeader.h:197
HttpHeader::needUpdate
bool needUpdate(const HttpHeader *fresh) const
Definition
HttpHeader.cc:377
HttpHeader::putRange
void putRange(const HttpHdrRange *range)
Definition
HttpHeader.cc:1175
HttpHeader::addEntry
void addEntry(HttpHeaderEntry *e)
Definition
HttpHeader.cc:869
HttpHeader::getContRange
HttpHdrContRange * getContRange() const
Definition
HttpHeader.cc:1394
HttpHeader::putInt64
void putInt64(Http::HdrType id, int64_t number)
Definition
HttpHeader.cc:1110
HttpHeader::removeConnectionHeaderEntries
void removeConnectionHeaderEntries()
Definition
HttpHeader.cc:1860
HttpHeader::getByName
String getByName(const SBuf &name) const
Definition
HttpHeader.cc:981
HttpHeader::getTime
time_t getTime(Http::HdrType id) const
Definition
HttpHeader.cc:1279
HttpHeader::getRange
HttpHdrRange * getRange() const
Definition
HttpHeader.cc:1353
HttpHeader::addVia
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=nullptr)
Definition
HttpHeader.cc:1078
HttpHeader::has
int has(Http::HdrType id) const
Definition
HttpHeader.cc:1070
HttpHeader::getInt64
int64_t getInt64(Http::HdrType id) const
Definition
HttpHeader.cc:1266
HttpHeader::getById
String getById(Http::HdrType id) const
Definition
HttpHeader.cc:990
HttpHeader::conflictingContentLength
bool conflictingContentLength() const
Definition
HttpHeader.h:113
HttpHeader::clean
void clean()
Definition
HttpHeader.cc:318
HttpHeader::hasNamed
bool hasNamed(const SBuf &s, String *value=nullptr) const
Definition
HttpHeader.cc:998
HttpHeader::getInt
int getInt(Http::HdrType id) const
Definition
HttpHeader.cc:1253
HttpHeader::findEntry
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition
HttpHeader.cc:735
HttpHeader::putAuth
void putAuth(const char *auth_scheme, const char *realm)
Definition
HttpHeader.cc:1137
HttpHeader::getLastStr
const char * getLastStr(Http::HdrType id) const
Definition
HttpHeader.cc:1312
HttpHeader::putExt
void putExt(const char *name, const char *value)
Definition
HttpHeader.cc:1208
HttpHeader::mask
HttpHeaderMask mask
Definition
HttpHeader.h:176
HttpHeader::putTime
void putTime(Http::HdrType id, time_t htime)
Definition
HttpHeader.cc:1119
HttpHeader::updateOrAddStr
void updateOrAddStr(Http::HdrType, const SBuf &)
Definition
HttpHeader.cc:1216
HttpHeader::getSc
HttpHdrSc * getSc() const
Definition
HttpHeader.cc:1372
HttpHeader::len
int len
Definition
HttpHeader.h:178
HttpHeader::packInto
void packInto(Packable *p, bool mask_sensitive_info=false) const
Definition
HttpHeader.cc:672
HttpHeader::findLastEntry
HttpHeaderEntry * findLastEntry(Http::HdrType id) const
Definition
HttpHeader.cc:760
HttpHeader::append
void append(const HttpHeader *src)
Definition
HttpHeader.cc:364
HttpHeader::skipUpdateHeader
bool skipUpdateHeader(const Http::HdrType id) const
Definition
HttpHeader.cc:391
HttpHeader::hasListMember
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition
HttpHeader.cc:1795
HttpHeader::delByName
int delByName(const SBuf &name)
Definition
HttpHeader.cc:780
Http::ContentLengthInterpreter
Definition
ContentLengthInterpreter.h:22
Packable
Definition
Packable.h:53
SBuf
Definition
SBuf.h:94
SBuf::length
size_type length() const
Returns the number of bytes stored in SBuf.
Definition
SBuf.h:419
String
Definition
SquidString.h:27
String::size
size_type size() const
Definition
SquidString.h:74
TimeOrTag
Definition
TimeOrTag.h:18
Http
Definition
forward.h:18
Http::SlowlyParseQuotedString
SBuf SlowlyParseQuotedString(const char *description, const char *start, size_t length)
Definition
HttpHeader.cc:268
Http::HdrType
HdrType
Definition
RegisteredHeaders.h:21
Http::TRANSFER_ENCODING
@ TRANSFER_ENCODING
Definition
RegisteredHeaders.h:99
forward.h
number
number
Definition
testStatHist.cc:32
squid
src
HttpHeader.h
Generated by
1.9.8