]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeaderTools.h
Docs: release notes for server_pconn_for_nonretriable
[thirdparty/squid.git] / src / HttpHeaderTools.h
CommitLineData
bbc27441 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
bbc27441
AJ
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
3b07476b
CT
9#ifndef SQUID_HTTPHEADERTOOLS_H
10#define SQUID_HTTPHEADERTOOLS_H
11
6f58d7d7 12#include "acl/forward.h"
f4698e0b 13#include "format/Format.h"
582c2af2 14#include "HttpHeader.h"
f4698e0b 15
620bc212 16#include <functional>
f4698e0b 17#include <list>
3b07476b 18#include <map>
3b07476b 19#include <string>
620bc212
AR
20#if HAVE_STRINGS_H
21#include <strings.h>
22#endif
3b07476b 23
f4698e0b 24class HeaderWithAcl;
001d55dc 25class HttpHeader;
001d55dc
FC
26class HttpRequest;
27class StoreEntry;
28class String;
29
f4698e0b
CT
30typedef std::list<HeaderWithAcl> HeaderWithAclList;
31
001d55dc
FC
32// Currently a POD
33class headerMangler
1b2f0924 34{
09bbee4c 35public:
3b07476b
CT
36 acl_access *access_list;
37 char *replacement;
38};
3b07476b 39
001d55dc 40/// A collection of headerMangler objects for a given message kind.
d3abcb0d
A
41class HeaderManglers
42{
3b07476b
CT
43public:
44 HeaderManglers();
45 ~HeaderManglers();
46
47 /// returns a header mangler for field e or nil if none was specified
001d55dc 48 const headerMangler *find(const HttpHeaderEntry &e) const;
3b07476b
CT
49
50 /// returns a mangler for the named header (known or custom)
001d55dc 51 headerMangler *track(const char *name);
3b07476b
CT
52
53 /// updates mangler for the named header with a replacement value
54 void setReplacement(const char *name, const char *replacementValue);
55
56 /// report the *_header_access part of the configuration
57 void dumpAccess(StoreEntry *entry, const char *optionName) const;
58 /// report the *_header_replace part of the configuration
59 void dumpReplacement(StoreEntry *entry, const char *optionName) const;
60
61private:
620bc212
AR
62 /// Case-insensitive std::string "less than" comparison functor.
63 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
6e422d23
A
64 class NoCaseLessThan: public std::binary_function<std::string, std::string, bool>
65 {
620bc212
AR
66 public:
67 bool operator()(const std::string &lhs, const std::string &rhs) const {
68 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
69 }
70 };
71
3b07476b 72 /// a name:mangler map; optimize: use unordered map or some such
620bc212 73 typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
3b07476b
CT
74
75 /// one mangler for each known header
81ab22b6 76 headerMangler known[static_cast<int>(Http::HdrType::enumEnd_)];
3b07476b
CT
77
78 /// one mangler for each custom header
79 ManglersByName custom;
80
81 /// configured if some mangling ACL applies to all header names
001d55dc 82 headerMangler all;
3b07476b
CT
83
84private:
85 /* not implemented */
86 HeaderManglers(const HeaderManglers &);
87 HeaderManglers &operator =(const HeaderManglers &);
88};
f4698e0b 89
f4698e0b
CT
90class HeaderWithAcl
91{
92public:
789217a2 93 HeaderWithAcl() : aclList(NULL), valueFormat(NULL), fieldId(Http::HdrType::BAD_HDR), quoted(false) {}
f4698e0b
CT
94
95 /// HTTP header field name
96 std::string fieldName;
97
98 /// HTTP header field value, possibly with macros
99 std::string fieldValue;
100
101 /// when the header field should be added (always if nil)
102 ACLList *aclList;
103
104 /// compiled HTTP header field value (no macros)
105 Format::Format *valueFormat;
106
107 /// internal ID for "known" headers or HDR_OTHER
789217a2 108 Http::HdrType fieldId;
f4698e0b
CT
109
110 /// whether fieldValue may contain macros
111 bool quoted;
112};
582c2af2 113
001d55dc 114int httpHeaderParseOffset(const char *start, int64_t * off);
fc54b8d2 115
001d55dc
FC
116int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive);
117int httpHeaderParseInt(const char *start, int *val);
789217a2 118void httpHeaderPutStrf(HttpHeader * hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3;
fc54b8d2 119
81858ebc 120const char *getStringPrefix(const char *str, size_t len);
1dff8715 121
001d55dc 122void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
f01162cf 123
3b07476b 124#endif
f53969cc 125