HttpHeader.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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_HTTPHEADER_H
10#define SQUID_HTTPHEADER_H
11
13#include "base/LookupTable.h"
15/* because we pass a spec by value */
16#include "HttpHeaderMask.h"
18#include "sbuf/forward.h"
19#include "SquidString.h"
20
21#include <vector>
22
23/* class forward declarations */
24class HttpHdrCc;
26class HttpHdrRange;
27class HttpHdrSc;
28class Packable;
29
31typedef enum {
33#if USE_HTCP
35#endif
38#if USE_OPENSSL
40#endif
41 hoEnd
43
45typedef ssize_t HttpHeaderPos;
46
47/* use this and only this to initialize HttpHeaderPos */
48#define HttpHeaderInitPos (-1)
49
51{
53
54public:
55 HttpHeaderEntry(Http::HdrType id, const SBuf &name, const char *value);
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
66};
67
68class ETag;
69class TimeOrTag;
70
72{
73
74public:
75 HttpHeader();
76 explicit HttpHeader(const http_hdr_owner_type owner);
77 HttpHeader(const HttpHeader &other);
79
80 HttpHeader &operator =(const HttpHeader &other);
81
82 /* Interface functions */
83 void clean();
84 void append(const HttpHeader * src);
87 void update(const HttpHeader *fresh);
89 bool needUpdate(const HttpHeader *fresh) const;
90 void compact();
91 int parse(const char *header_start, size_t len, Http::ContentLengthInterpreter &interpreter);
96 int parse(const char *buf, size_t buf_len, bool atEnd, size_t &hdr_sz, Http::ContentLengthInterpreter &interpreter);
97 void packInto(Packable * p, bool mask_sensitive_info=false) const;
102 int delByName(const SBuf &name);
104 int delByName(const char *name) { return delByName(SBuf(name)); }
105 int delById(Http::HdrType id);
106 void delAt(HttpHeaderPos pos, int &headers_deleted);
107 void refreshMask();
108 void addEntry(HttpHeaderEntry * e);
110 String getList(Http::HdrType id) const;
111 bool getList(Http::HdrType id, String *s) const;
114 String getByName(const SBuf &name) const;
115 String getByName(const char *name) const;
116 String getById(Http::HdrType id) const;
119 bool getByIdIfPresent(Http::HdrType id, String *result) const;
122 bool hasNamed(const SBuf &s, String *value = nullptr) const;
124 bool hasNamed(const char *name, unsigned int namelen, String *value = nullptr) const;
127 SBuf getByNameListMember(const char *name, const char *member, const char separator) const;
130 SBuf getListMember(Http::HdrType id, const char *member, const char separator) const;
131 int has(Http::HdrType id) const;
134 void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from = nullptr);
135 void putInt(Http::HdrType id, int number);
136 void putInt64(Http::HdrType id, int64_t number);
137 void putTime(Http::HdrType id, time_t htime);
138 void putStr(Http::HdrType id, const char *str);
139 void putAuth(const char *auth_scheme, const char *realm);
140 void putCc(const HttpHdrCc * cc);
141 void putContRange(const HttpHdrContRange * cr);
142 void putRange(const HttpHdrRange * range);
143 void putSc(HttpHdrSc *sc);
144 void putExt(const char *name, const char *value);
145
148 void updateOrAddStr(Http::HdrType, const SBuf &);
149
150 int getInt(Http::HdrType id) const;
151 int64_t getInt64(Http::HdrType id) const;
152 time_t getTime(Http::HdrType id) const;
153 const char *getStr(Http::HdrType id) const;
154 const char *getLastStr(Http::HdrType id) const;
155 HttpHdrCc *getCc() const;
156 HttpHdrRange *getRange() const;
157 HttpHdrSc *getSc() const;
159 SBuf getAuthToken(Http::HdrType id, const char *auth_scheme) const;
160 ETag getETag(Http::HdrType id) const;
162 int hasListMember(Http::HdrType id, const char *member, const char separator) const;
163 int hasByNameListMember(const char *name, const char *member, const char separator) const;
165
169
171 bool unsupportedTe() const { return teUnsupported_; }
172
173 /* protected, do not use these, use interface functions instead */
174 std::vector<HttpHeaderEntry*, PoolingAllocator<HttpHeaderEntry*> > entries;
177 int len;
179protected:
188 static bool Isolate(const char **parse_start, size_t l, const char **blk_start, const char **blk_end);
189 bool skipUpdateHeader(const Http::HdrType id) const;
190
191private:
196 bool teUnsupported_ = false;
197};
198
199int httpHeaderParseQuotedString(const char *start, const int len, String *val);
200
202SBuf httpHeaderQuoteString(const char *raw);
203
204void httpHeaderCalcMask(HttpHeaderMask * mask, Http::HdrType http_hdr_type_enums[], size_t count);
205
206void httpHeaderInitModule(void);
207
208#endif /* SQUID_HTTPHEADER_H */
209
char HttpHeaderMask[12]
SBuf httpHeaderQuoteString(const char *raw)
quotes string using RFC 7230 quoted-string rules
http_hdr_owner_type
Definition: HttpHeader.h:31
@ hoRequest
Definition: HttpHeader.h:36
@ hoNone
Definition: HttpHeader.h:32
@ hoReply
Definition: HttpHeader.h:37
@ hoHtcpReply
Definition: HttpHeader.h:34
@ hoEnd
Definition: HttpHeader.h:41
@ hoErrorDetail
Definition: HttpHeader.h:39
void httpHeaderCalcMask(HttpHeaderMask *mask, Http::HdrType http_hdr_type_enums[], size_t count)
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
int httpHeaderParseQuotedString(const char *start, const int len, String *val)
void httpHeaderInitModule(void)
Definition: HttpHeader.cc:121
Definition: ETag.h:18
void packInto(Packable *p) const
Definition: HttpHeader.cc:1545
static HttpHeaderEntry * parse(const char *field_start, const char *field_end, const http_hdr_owner_type msgType)
Definition: HttpHeader.cc:1425
int getInt() const
Definition: HttpHeader.cc:1555
HttpHeaderEntry * clone() const
Definition: HttpHeader.cc:1539
MEMPROXY_CLASS(HttpHeaderEntry)
int64_t getInt64() const
Definition: HttpHeader.cc:1567
HttpHeaderEntry(Http::HdrType id, const SBuf &name, const char *value)
Definition: HttpHeader.cc:1393
Http::HdrType id
Definition: HttpHeader.h:63
SBuf getByNameListMember(const char *name, const char *member, const char separator) const
Definition: HttpHeader.cc:949
void removeHopByHopEntries()
Definition: HttpHeader.cc:1743
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1027
TimeOrTag getTimeOrTag(Http::HdrType id) const
Definition: HttpHeader.cc:1363
HttpHdrCc * getCc() const
Definition: HttpHeader.cc:1227
bool getByIdIfPresent(Http::HdrType id, String *result) const
Definition: HttpHeader.cc:903
int hasByNameListMember(const char *name, const char *member, const char separator) const
Definition: HttpHeader.cc:1719
bool chunked() const
Definition: HttpHeader.h:168
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:701
bool unsupportedTe() const
whether message used an unsupported and/or invalid Transfer-Encoding
Definition: HttpHeader.h:171
int parse(const char *header_start, size_t len, Http::ContentLengthInterpreter &interpreter)
Definition: HttpHeader.cc:356
SBuf getListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:960
String getStrOrList(Http::HdrType id) const
Definition: HttpHeader.cc:854
ETag getETag(Http::HdrType id) const
Definition: HttpHeader.cc:1350
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1000
void compact()
Definition: HttpHeader.cc:718
http_hdr_owner_type owner
Definition: HttpHeader.h:176
int delById(Http::HdrType id)
Definition: HttpHeader.cc:673
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:820
bool conflictingContentLength_
Definition: HttpHeader.h:193
void putContRange(const HttpHdrContRange *cr)
Definition: HttpHeader.cc:1059
void refreshMask()
Definition: HttpHeader.cc:729
void update(const HttpHeader *fresh)
Definition: HttpHeader.cc:274
SBuf getAuthToken(Http::HdrType id, const char *auth_scheme) const
Definition: HttpHeader.cc:1308
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:590
static bool Isolate(const char **parse_start, size_t l, const char **blk_start, const char **blk_end)
Definition: HttpHeader.cc:308
void putCc(const HttpHdrCc *cc)
Definition: HttpHeader.cc:1043
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1196
int delByName(const char *name)
Definition: HttpHeader.h:104
std::vector< HttpHeaderEntry *, PoolingAllocator< HttpHeaderEntry * > > entries
Definition: HttpHeader.h:174
HttpHeader & operator=(const HttpHeader &other)
Definition: HttpHeader.cc:177
void putSc(HttpHdrSc *sc)
Definition: HttpHeader.cc:1091
bool teUnsupported_
Definition: HttpHeader.h:196
bool needUpdate(const HttpHeader *fresh) const
Definition: HttpHeader.cc:251
void putRange(const HttpHdrRange *range)
Definition: HttpHeader.cc:1075
void addEntry(HttpHeaderEntry *e)
Definition: HttpHeader.cc:743
HttpHdrContRange * getContRange() const
Definition: HttpHeader.cc:1294
void putInt64(Http::HdrType id, int64_t number)
Definition: HttpHeader.cc:1009
void removeConnectionHeaderEntries()
Definition: HttpHeader.cc:1760
String getByName(const SBuf &name) const
Definition: HttpHeader.cc:880
time_t getTime(Http::HdrType id) const
Definition: HttpHeader.cc:1179
HttpHdrRange * getRange() const
Definition: HttpHeader.cc:1253
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=nullptr)
Definition: HttpHeader.cc:977
int has(Http::HdrType id) const
Definition: HttpHeader.cc:969
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1166
String getById(Http::HdrType id) const
Definition: HttpHeader.cc:889
void insertEntry(HttpHeaderEntry *e)
Definition: HttpHeader.cc:769
bool conflictingContentLength() const
Definition: HttpHeader.h:112
void clean()
Definition: HttpHeader.cc:192
bool hasNamed(const SBuf &s, String *value=nullptr) const
Definition: HttpHeader.cc:897
int getInt(Http::HdrType id) const
Definition: HttpHeader.cc:1153
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:609
void putAuth(const char *auth_scheme, const char *realm)
Definition: HttpHeader.cc:1036
const char * getLastStr(Http::HdrType id) const
Definition: HttpHeader.cc:1212
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1108
HttpHeaderMask mask
Definition: HttpHeader.h:175
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1018
void updateOrAddStr(Http::HdrType, const SBuf &)
Definition: HttpHeader.cc:1116
HttpHdrSc * getSc() const
Definition: HttpHeader.cc:1272
void packInto(Packable *p, bool mask_sensitive_info=false) const
Definition: HttpHeader.cc:546
HttpHeaderEntry * findLastEntry(Http::HdrType id) const
Definition: HttpHeader.cc:634
void append(const HttpHeader *src)
Definition: HttpHeader.cc:238
bool skipUpdateHeader(const Http::HdrType id) const
Definition: HttpHeader.cc:265
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1695
int delByName(const SBuf &name)
Definition: HttpHeader.cc:654
Definition: SBuf.h:94
@ TRANSFER_ENCODING
static int sc[16]
Definition: smbdes.c:121
number
Definition: testStatHist.cc:32

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors