]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderTools.h
1 #ifndef SQUID_HTTPHEADERTOOLS_H
2 #define SQUID_HTTPHEADERTOOLS_H
4 #include "acl/forward.h"
5 #include "format/Format.h"
6 #include "HttpHeader.h"
19 class HttpHeaderFieldInfo
;
24 typedef std::list
<HeaderWithAcl
> HeaderWithAclList
;
30 acl_access
*access_list
;
34 /// A collection of headerMangler objects for a given message kind.
41 /// returns a header mangler for field e or nil if none was specified
42 const headerMangler
*find(const HttpHeaderEntry
&e
) const;
44 /// returns a mangler for the named header (known or custom)
45 headerMangler
*track(const char *name
);
47 /// updates mangler for the named header with a replacement value
48 void setReplacement(const char *name
, const char *replacementValue
);
50 /// report the *_header_access part of the configuration
51 void dumpAccess(StoreEntry
*entry
, const char *optionName
) const;
52 /// report the *_header_replace part of the configuration
53 void dumpReplacement(StoreEntry
*entry
, const char *optionName
) const;
56 /// Case-insensitive std::string "less than" comparison functor.
57 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
58 class NoCaseLessThan
: public std::binary_function
<std::string
, std::string
, bool>
61 bool operator()(const std::string
&lhs
, const std::string
&rhs
) const {
62 return strcasecmp(lhs
.c_str(), rhs
.c_str()) < 0;
66 /// a name:mangler map; optimize: use unordered map or some such
67 typedef std::map
<std::string
, headerMangler
, NoCaseLessThan
> ManglersByName
;
69 /// one mangler for each known header
70 headerMangler known
[HDR_ENUM_END
];
72 /// one mangler for each custom header
73 ManglersByName custom
;
75 /// configured if some mangling ACL applies to all header names
80 HeaderManglers(const HeaderManglers
&);
81 HeaderManglers
&operator =(const HeaderManglers
&);
87 HeaderWithAcl() : aclList(NULL
), valueFormat(NULL
), fieldId(HDR_BAD_HDR
), quoted(false) {}
89 /// HTTP header field name
90 std::string fieldName
;
92 /// HTTP header field value, possibly with macros
93 std::string fieldValue
;
95 /// when the header field should be added (always if nil)
98 /// compiled HTTP header field value (no macros)
99 Format::Format
*valueFormat
;
101 /// internal ID for "known" headers or HDR_OTHER
102 http_hdr_type fieldId
;
104 /// whether fieldValue may contain macros
108 int httpHeaderParseOffset(const char *start
, int64_t * off
);
110 HttpHeaderFieldInfo
*httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs
* attrs
, int count
);
111 void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo
* info
, int count
);
112 http_hdr_type
httpHeaderIdByName(const char *name
, size_t name_len
, const HttpHeaderFieldInfo
* attrs
, int end
);
113 http_hdr_type
httpHeaderIdByNameDef(const char *name
, int name_len
);
114 const char *httpHeaderNameById(int id
);
115 int httpHeaderHasConnDir(const HttpHeader
* hdr
, const char *directive
);
116 int httpHeaderParseInt(const char *start
, int *val
);
117 void httpHeaderPutStrf(HttpHeader
* hdr
, http_hdr_type id
, const char *fmt
,...) PRINTF_FORMAT_ARG3
;
119 const char *getStringPrefix(const char *str
, const char *end
);
121 void httpHdrMangleList(HttpHeader
*, HttpRequest
*, int req_or_rep
);