]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderTools.h
2 * Copyright (C) 1996-2014 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"
27 class HttpHeaderFieldInfo
;
32 typedef std::list
<HeaderWithAcl
> HeaderWithAclList
;
38 acl_access
*access_list
;
42 /// A collection of headerMangler objects for a given message kind.
49 /// returns a header mangler for field e or nil if none was specified
50 const headerMangler
*find(const HttpHeaderEntry
&e
) const;
52 /// returns a mangler for the named header (known or custom)
53 headerMangler
*track(const char *name
);
55 /// updates mangler for the named header with a replacement value
56 void setReplacement(const char *name
, const char *replacementValue
);
58 /// report the *_header_access part of the configuration
59 void dumpAccess(StoreEntry
*entry
, const char *optionName
) const;
60 /// report the *_header_replace part of the configuration
61 void dumpReplacement(StoreEntry
*entry
, const char *optionName
) const;
64 /// Case-insensitive std::string "less than" comparison functor.
65 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
66 class NoCaseLessThan
: public std::binary_function
<std::string
, std::string
, bool>
69 bool operator()(const std::string
&lhs
, const std::string
&rhs
) const {
70 return strcasecmp(lhs
.c_str(), rhs
.c_str()) < 0;
74 /// a name:mangler map; optimize: use unordered map or some such
75 typedef std::map
<std::string
, headerMangler
, NoCaseLessThan
> ManglersByName
;
77 /// one mangler for each known header
78 headerMangler known
[HDR_ENUM_END
];
80 /// one mangler for each custom header
81 ManglersByName custom
;
83 /// configured if some mangling ACL applies to all header names
88 HeaderManglers(const HeaderManglers
&);
89 HeaderManglers
&operator =(const HeaderManglers
&);
95 HeaderWithAcl() : aclList(NULL
), valueFormat(NULL
), fieldId(HDR_BAD_HDR
), quoted(false) {}
97 /// HTTP header field name
98 std::string fieldName
;
100 /// HTTP header field value, possibly with macros
101 std::string fieldValue
;
103 /// when the header field should be added (always if nil)
106 /// compiled HTTP header field value (no macros)
107 Format::Format
*valueFormat
;
109 /// internal ID for "known" headers or HDR_OTHER
110 http_hdr_type fieldId
;
112 /// whether fieldValue may contain macros
116 int httpHeaderParseOffset(const char *start
, int64_t * off
);
118 HttpHeaderFieldInfo
*httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs
* attrs
, int count
);
119 void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo
* info
, int count
);
120 http_hdr_type
httpHeaderIdByName(const char *name
, size_t name_len
, const HttpHeaderFieldInfo
* attrs
, int end
);
121 http_hdr_type
httpHeaderIdByNameDef(const char *name
, int name_len
);
122 const char *httpHeaderNameById(int id
);
123 int httpHeaderHasConnDir(const HttpHeader
* hdr
, const char *directive
);
124 int httpHeaderParseInt(const char *start
, int *val
);
125 void httpHeaderPutStrf(HttpHeader
* hdr
, http_hdr_type id
, const char *fmt
,...) PRINTF_FORMAT_ARG3
;
127 const char *getStringPrefix(const char *str
, size_t len
);
129 void httpHdrMangleList(HttpHeader
*, HttpRequest
*, int req_or_rep
);