HttpHeaderTools.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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
9#ifndef SQUID_HTTPHEADERTOOLS_H
10#define SQUID_HTTPHEADERTOOLS_H
11
12#include "acl/forward.h"
13#include "format/Format.h"
14#include "HttpHeader.h"
15#include "sbuf/forward.h"
16
17#include <functional>
18#include <list>
19#include <map>
20#include <string>
21#if HAVE_STRINGS_H
22#include <strings.h>
23#endif
24
25class HeaderWithAcl;
26class HttpHeader;
27class HttpRequest;
28class StoreEntry;
29
30typedef std::list<HeaderWithAcl> HeaderWithAclList;
31
32/* Distinguish between Request and Reply (for header mangling) */
33typedef enum {
37
38// Currently a POD
40{
41public:
44};
45
48{
49public:
52
54 const headerMangler *find(const HttpHeaderEntry &e) const;
55
57 headerMangler *track(const char *name);
58
60 void setReplacement(const char *name, const char *replacementValue);
61
63 void dumpAccess(StoreEntry *entry, const char *optionName) const;
65 void dumpReplacement(StoreEntry *entry, const char *optionName) const;
66
67private:
71 {
72 public:
73 bool operator()(const std::string &lhs, const std::string &rhs) const {
74 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
75 }
76 };
77
79 typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
80
83
86
89
90private:
91 /* not implemented */
94};
95
97{
98public:
99 HeaderWithAcl() : aclList(nullptr), valueFormat(nullptr), fieldId(Http::HdrType::BAD_HDR), quoted(false) {}
100
102 std::string fieldName;
103
105 std::string fieldValue;
106
109
112
115
117 bool quoted;
118};
119
126bool httpHeaderParseOffset(const char *start, int64_t *offPtr, char **endPtr = nullptr);
127
128bool httpHeaderHasConnDir(const HttpHeader * hdr, const SBuf &directive);
129int httpHeaderParseInt(const char *start, int *val);
130void httpHeaderPutStrf(HttpHeader * hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3;
131
132const char *getStringPrefix(const char *str, size_t len);
133
135
136#endif
137
req_or_rep_t
@ ROR_REPLY
@ ROR_REQUEST
void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
bool httpHeaderParseOffset(const char *start, int64_t *offPtr, char **endPtr=nullptr)
int httpHeaderParseInt(const char *start, int *val)
const char * getStringPrefix(const char *str, size_t len)
std::list< HeaderWithAcl > HeaderWithAclList
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3
bool httpHeaderHasConnDir(const HttpHeader *hdr, const SBuf &directive)
#define acl_access
Definition: forward.h:45
#define ACLList
Definition: forward.h:46
bool operator()(const std::string &lhs, const std::string &rhs) const
A collection of headerMangler objects for a given message kind.
HeaderManglers & operator=(const HeaderManglers &)
void dumpAccess(StoreEntry *entry, const char *optionName) const
report the *_header_access part of the configuration
HeaderManglers(const HeaderManglers &)
const headerMangler * find(const HttpHeaderEntry &e) const
returns a header mangler for field e or nil if none was specified
void setReplacement(const char *name, const char *replacementValue)
updates mangler for the named header with a replacement value
ManglersByName custom
one mangler for each custom header
std::map< std::string, headerMangler, NoCaseLessThan > ManglersByName
a name:mangler map; optimize: use unordered map or some such
headerMangler all
configured if some mangling ACL applies to all header names
headerMangler * track(const char *name)
returns a mangler for the named header (known or custom)
void dumpReplacement(StoreEntry *entry, const char *optionName) const
report the *_header_replace part of the configuration
headerMangler known[static_cast< int >(Http::HdrType::enumEnd_)]
one mangler for each known header
ACLList * aclList
when the header field should be added (always if nil)
Http::HdrType fieldId
internal ID for "known" headers or HDR_OTHER
bool quoted
whether fieldValue may contain macros
std::string fieldName
HTTP header field name.
Format::Format * valueFormat
compiled HTTP header field value (no macros)
std::string fieldValue
HTTP header field value, possibly with macros.
Definition: SBuf.h:94
acl_access * access_list
#define PRINTF_FORMAT_ARG3
Definition: forward.h:18

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors