]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderTools.h
fd1940dcbb88e1b34b609090574905bfb98bfac2
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_HTTPHEADERTOOLS_H
10 #define SQUID_HTTPHEADERTOOLS_H
12 #include "acl/forward.h"
13 #include "format/Format.h"
14 #include "HttpHeader.h"
30 typedef std::list
<HeaderWithAcl
> HeaderWithAclList
;
36 acl_access
*access_list
;
40 /// A collection of headerMangler objects for a given message kind.
47 /// returns a header mangler for field e or nil if none was specified
48 const headerMangler
*find(const HttpHeaderEntry
&e
) const;
50 /// returns a mangler for the named header (known or custom)
51 headerMangler
*track(const char *name
);
53 /// updates mangler for the named header with a replacement value
54 void setReplacement(const char *name
, const char *replacementValue
);
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;
62 /// Case-insensitive std::string "less than" comparison functor.
63 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
64 class NoCaseLessThan
: public std::binary_function
<std::string
, std::string
, bool>
67 bool operator()(const std::string
&lhs
, const std::string
&rhs
) const {
68 return strcasecmp(lhs
.c_str(), rhs
.c_str()) < 0;
72 /// a name:mangler map; optimize: use unordered map or some such
73 typedef std::map
<std::string
, headerMangler
, NoCaseLessThan
> ManglersByName
;
75 /// one mangler for each known header
76 headerMangler known
[static_cast<int>(Http::HdrType::ENUM_END
)];
78 /// one mangler for each custom header
79 ManglersByName custom
;
81 /// configured if some mangling ACL applies to all header names
86 HeaderManglers(const HeaderManglers
&);
87 HeaderManglers
&operator =(const HeaderManglers
&);
93 HeaderWithAcl() : aclList(NULL
), valueFormat(NULL
), fieldId(Http::HdrType::BAD_HDR
), quoted(false) {}
95 /// HTTP header field name
96 std::string fieldName
;
98 /// HTTP header field value, possibly with macros
99 std::string fieldValue
;
101 /// when the header field should be added (always if nil)
104 /// compiled HTTP header field value (no macros)
105 Format::Format
*valueFormat
;
107 /// internal ID for "known" headers or HDR_OTHER
108 Http::HdrType fieldId
;
110 /// whether fieldValue may contain macros
114 int httpHeaderParseOffset(const char *start
, int64_t * off
);
116 int httpHeaderHasConnDir(const HttpHeader
* hdr
, const char *directive
);
117 int httpHeaderParseInt(const char *start
, int *val
);
118 void httpHeaderPutStrf(HttpHeader
* hdr
, Http::HdrType id
, const char *fmt
,...) PRINTF_FORMAT_ARG3
;
120 const char *getStringPrefix(const char *str
, size_t len
);
122 void httpHdrMangleList(HttpHeader
*, HttpRequest
*, int req_or_rep
);