1 #ifndef SQUID_HTTPHEADERTOOLS_H
2 #define SQUID_HTTPHEADERTOOLS_H
4 #include "format/Format.h"
5 #include "HttpHeader.h"
19 typedef std::list
<HeaderWithAcl
> HeaderWithAclList
;
22 struct _header_mangler
{
23 acl_access
*access_list
;
26 typedef struct _header_mangler header_mangler
;
30 /// A collection of header_mangler objects for a given message kind.
37 /// returns a header mangler for field e or nil if none was specified
38 const header_mangler
*find(const HttpHeaderEntry
&e
) const;
40 /// returns a mangler for the named header (known or custom)
41 header_mangler
*track(const char *name
);
43 /// updates mangler for the named header with a replacement value
44 void setReplacement(const char *name
, const char *replacementValue
);
46 /// report the *_header_access part of the configuration
47 void dumpAccess(StoreEntry
*entry
, const char *optionName
) const;
48 /// report the *_header_replace part of the configuration
49 void dumpReplacement(StoreEntry
*entry
, const char *optionName
) const;
52 /// a name:mangler map; optimize: use unordered map or some such
53 typedef std::map
<std::string
, header_mangler
> ManglersByName
;
55 /// one mangler for each known header
56 header_mangler known
[HDR_ENUM_END
];
58 /// one mangler for each custom header
59 ManglersByName custom
;
61 /// configured if some mangling ACL applies to all header names
66 HeaderManglers(const HeaderManglers
&);
67 HeaderManglers
&operator =(const HeaderManglers
&);
74 HeaderWithAcl() : aclList(NULL
), fieldId (HDR_BAD_HDR
), quoted(false) {}
76 /// HTTP header field name
77 std::string fieldName
;
79 /// HTTP header field value, possibly with macros
80 std::string fieldValue
;
82 /// when the header field should be added (always if nil)
85 /// compiled HTTP header field value (no macros)
86 Format::Format
*valueFormat
;
88 /// internal ID for "known" headers or HDR_OTHER
89 http_hdr_type fieldId
;
91 /// whether fieldValue may contain macros
95 extern int httpHeaderParseOffset(const char *start
, int64_t * off
);
97 class HttpHeaderFieldInfo
;
102 extern HttpHeaderFieldInfo
*httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs
* attrs
, int count
);
103 extern void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo
* info
, int count
);
104 extern http_hdr_type
httpHeaderIdByName(const char *name
, size_t name_len
, const HttpHeaderFieldInfo
* attrs
, int end
);
105 extern http_hdr_type
httpHeaderIdByNameDef(const char *name
, int name_len
);
106 extern const char *httpHeaderNameById(int id
);
107 extern int httpHeaderHasConnDir(const HttpHeader
* hdr
, const char *directive
);
108 extern int httpHeaderParseInt(const char *start
, int *val
);
109 extern void httpHeaderPutStrf(HttpHeader
* hdr
, http_hdr_type id
, const char *fmt
,...) PRINTF_FORMAT_ARG3
;
111 extern const char *getStringPrefix(const char *str
, const char *end
);
113 extern void httpHdrMangleList(HttpHeader
*, HttpRequest
*, int req_or_rep
);