HttpHeader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
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/forward.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
35 #endif
38 #if USE_OPENSSL
40 #endif
43 
45 typedef ssize_t HttpHeaderPos;
46 
47 /* use this and only this to initialize HttpHeaderPos */
48 #define HttpHeaderInitPos (-1)
49 
51 {
53 
54 public:
55  HttpHeaderEntry(Http::HdrType id, const SBuf &name, const char *value);
57  static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
58  HttpHeaderEntry *clone() const;
59  void packInto(Packable *p) const;
60  int getInt() const;
61  int64_t getInt64() const;
62 
66 };
67 
68 class ETag;
69 class TimeOrTag;
70 
72 {
73 
74 public:
75  HttpHeader();
76  explicit HttpHeader(const http_hdr_owner_type owner);
77  HttpHeader(const HttpHeader &other);
78  ~HttpHeader();
79 
80  HttpHeader &operator =(const HttpHeader &other);
81 
82  /* Interface functions */
83  void clean();
84  void append(const HttpHeader * src);
85  bool update(HttpHeader const *fresh);
86  void compact();
87  int parse(const char *header_start, size_t len);
92  int parse(const char *buf, size_t buf_len, bool atEnd, size_t &hdr_sz);
93  void packInto(Packable * p, bool mask_sensitive_info=false) const;
98  int delByName(const SBuf &name);
100  int delByName(const char *name) { return delByName(SBuf(name)); }
101  int delById(Http::HdrType id);
102  void delAt(HttpHeaderPos pos, int &headers_deleted);
103  void refreshMask();
104  void addEntry(HttpHeaderEntry * e);
105  void insertEntry(HttpHeaderEntry * e);
106  String getList(Http::HdrType id) const;
107  bool getList(Http::HdrType id, String *s) const;
110  String getByName(const SBuf &name) const;
111  String getByName(const char *name) const;
112  String getById(Http::HdrType id) const;
115  bool getByIdIfPresent(Http::HdrType id, String *result) const;
118  bool hasNamed(const SBuf &s, String *value = 0) const;
120  bool hasNamed(const char *name, unsigned int namelen, String *value = 0) const;
121  String getByNameListMember(const char *name, const char *member, const char separator) const;
122  String getListMember(Http::HdrType id, const char *member, const char separator) const;
123  int has(Http::HdrType id) const;
126  void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from = 0);
127  void putInt(Http::HdrType id, int number);
128  void putInt64(Http::HdrType id, int64_t number);
129  void putTime(Http::HdrType id, time_t htime);
130  void putStr(Http::HdrType id, const char *str);
131  void putAuth(const char *auth_scheme, const char *realm);
132  void putCc(const HttpHdrCc * cc);
133  void putContRange(const HttpHdrContRange * cr);
134  void putRange(const HttpHdrRange * range);
135  void putSc(HttpHdrSc *sc);
136  void putWarning(const int code, const char *const text);
137  void putExt(const char *name, const char *value);
138  int getInt(Http::HdrType id) const;
139  int64_t getInt64(Http::HdrType id) const;
140  time_t getTime(Http::HdrType id) const;
141  const char *getStr(Http::HdrType id) const;
142  const char *getLastStr(Http::HdrType id) const;
143  HttpHdrCc *getCc() const;
144  HttpHdrRange *getRange() const;
145  HttpHdrSc *getSc() const;
147  const char *getAuth(Http::HdrType id, const char *auth_scheme) const;
148  ETag getETag(Http::HdrType id) const;
150  int hasListMember(Http::HdrType id, const char *member, const char separator) const;
151  int hasByNameListMember(const char *name, const char *member, const char separator) const;
152  void removeHopByHopEntries();
153  inline bool chunked() const;
154 
155  /* protected, do not use these, use interface functions instead */
156  std::vector<HttpHeaderEntry *> entries;
159  int len;
161 protected:
170  static bool Isolate(const char **parse_start, size_t l, const char **blk_start, const char **blk_end);
171  bool needUpdate(const HttpHeader *fresh) const;
172  bool skipUpdateHeader(const Http::HdrType id) const;
173  void updateWarnings();
174 
175 private:
178 };
179 
180 int httpHeaderParseQuotedString(const char *start, const int len, String *val);
181 
183 SBuf httpHeaderQuoteString(const char *raw);
184 
185 void httpHeaderCalcMask(HttpHeaderMask * mask, Http::HdrType http_hdr_type_enums[], size_t count);
186 
187 inline bool
189 {
192 }
193 
194 void httpHeaderInitModule(void);
195 
196 #endif /* SQUID_HTTPHEADER_H */
197 
int delById(Http::HdrType id)
Definition: HttpHeader.cc:672
void removeConnectionHeaderEntries()
Definition: HttpHeader.cc:1730
int has(Http::HdrType id) const
Definition: HttpHeader.cc:1002
bool needUpdate(const HttpHeader *fresh) const
check whether the fresh header has any new/changed updatable fields
Definition: HttpHeader.cc:246
String getListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:976
static int sc[16]
Definition: smbdes.c:121
http_hdr_owner_type
Definition: HttpHeader.h:31
HttpHdrCc * getCc() const
Definition: HttpHeader.cc:1234
bool hasNamed(const SBuf &s, String *value=0) const
Definition: HttpHeader.cc:896
Definition: ETag.h:17
int httpHeaderParseQuotedString(const char *start, const int len, String *val)
void httpHeaderCalcMask(HttpHeaderMask *mask, Http::HdrType http_hdr_type_enums[], size_t count)
Definition: SBuf.h:87
void putContRange(const HttpHdrContRange *cr)
Definition: HttpHeader.cc:1095
std::vector< HttpHeaderEntry * > entries
Definition: HttpHeader.h:156
int delByName(const SBuf &name)
Definition: HttpHeader.cc:653
void removeHopByHopEntries()
Definition: HttpHeader.cc:1713
static bool Isolate(const char **parse_start, size_t l, const char **blk_start, const char **blk_end)
Definition: HttpHeader.cc:322
HttpHeaderMask mask
Definition: HttpHeader.h:157
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1152
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:589
bool conflictingContentLength_
found different Content-Length fields
Definition: HttpHeader.h:177
int64_t getInt64() const
Definition: HttpHeader.cc:1538
HttpHdrRange * getRange() const
Definition: HttpHeader.cc:1263
char * p
Definition: membanger.c:43
int getInt() const
Definition: HttpHeader.cc:1526
String getByName(const SBuf &name) const
Definition: HttpHeader.cc:879
int getInt(Http::HdrType id) const
Definition: HttpHeader.cc:1160
bool skipUpdateHeader(const Http::HdrType id) const
Definition: HttpHeader.cc:273
Http::HdrType id
Definition: HttpHeader.h:63
int hasByNameListMember(const char *name, const char *member, const char separator) const
Definition: HttpHeader.cc:1689
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:700
void append(const HttpHeader *src)
Definition: HttpHeader.cc:232
TimeOrTag getTimeOrTag(Http::HdrType id) const
Definition: HttpHeader.cc:1370
const char * getAuth(Http::HdrType id, const char *auth_scheme) const
Definition: HttpHeader.cc:1318
const char * getLastStr(Http::HdrType id) const
Definition: HttpHeader.cc:1219
String getByNameListMember(const char *name, const char *member, const char separator) const
Definition: HttpHeader.cc:948
MEMPROXY_CLASS(HttpHeaderEntry)
HttpHdrSc * getSc() const
Definition: HttpHeader.cc:1282
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:608
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1173
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1054
HttpHeaderEntry(Http::HdrType id, const SBuf &name, const char *value)
Definition: HttpHeader.cc:1400
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:819
int delByName(const char *name)
Definition: HttpHeader.h:100
http_hdr_owner_type owner
Definition: HttpHeader.h:158
char HttpHeaderMask[12]
void putSc(HttpHdrSc *sc)
Definition: HttpHeader.cc:1127
void putWarning(const int code, const char *const text)
add a Warning header
Definition: HttpHeader.cc:1143
int parse(const char *header_start, size_t len)
Definition: HttpHeader.cc:367
bool update(HttpHeader const *fresh)
Definition: HttpHeader.cc:280
void refreshMask()
Definition: HttpHeader.cc:728
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1036
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1665
HttpHeaderEntry * findLastEntry(Http::HdrType id) const
Definition: HttpHeader.cc:633
String getById(Http::HdrType id) const
Definition: HttpHeader.cc:888
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=0)
Definition: HttpHeader.cc:1010
unsigned char code
Definition: html_quote.c:20
void const char * buf
Definition: stub_helper.cc:16
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
String getStrOrList(Http::HdrType id) const
Definition: HttpHeader.cc:853
void packInto(Packable *p) const
Definition: HttpHeader.cc:1516
bool conflictingContentLength() const
Definition: HttpHeader.h:108
void putInt64(Http::HdrType id, int64_t number)
Definition: HttpHeader.cc:1045
number
Definition: testStatHist.cc:16
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1063
void clean()
Definition: HttpHeader.cc:184
void putCc(const HttpHdrCc *cc)
Definition: HttpHeader.cc:1079
void updateWarnings()
Definition: HttpHeader.cc:260
HttpHeader & operator=(const HttpHeader &other)
Definition: HttpHeader.cc:170
void compact()
Definition: HttpHeader.cc:717
bool chunked() const
whether message uses chunked Transfer-Encoding
Definition: HttpHeader.h:188
time_t getTime(Http::HdrType id) const
Definition: HttpHeader.cc:1186
void packInto(Packable *p, bool mask_sensitive_info=false) const
Definition: HttpHeader.cc:545
static HttpHeaderEntry * parse(const char *field_start, const char *field_end)
Definition: HttpHeader.cc:1432
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1203
HttpHdrContRange * getContRange() const
Definition: HttpHeader.cc:1304
void addEntry(HttpHeaderEntry *e)
Definition: HttpHeader.cc:742
void insertEntry(HttpHeaderEntry *e)
Definition: HttpHeader.cc:768
SBuf httpHeaderQuoteString(const char *raw)
quotes string using RFC 7230 quoted-string rules
void putRange(const HttpHdrRange *range)
Definition: HttpHeader.cc:1111
void putAuth(const char *auth_scheme, const char *realm)
Definition: HttpHeader.cc:1072
const char * text
Definition: errorpage.cc:80
bool getByIdIfPresent(Http::HdrType id, String *result) const
Definition: HttpHeader.cc:902
HttpHeaderEntry * clone() const
Definition: HttpHeader.cc:1510
void httpHeaderInitModule(void)
Definition: HttpHeader.cc:119
ETag getETag(Http::HdrType id) const
Definition: HttpHeader.cc:1357

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors