/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#ifndef SQUID_HTTPHEADER_H
#define SQUID_HTTPHEADER_H
+#include "anyp/ProtocolVersion.h"
#include "base/LookupTable.h"
#include "http/RegisteredHeaders.h"
/* because we pass a spec by value */
MEMPROXY_CLASS(HttpHeaderEntry);
public:
- HttpHeaderEntry(Http::HdrType id, const char *name, const char *value);
+ HttpHeaderEntry(Http::HdrType id, const SBuf &name, const char *value);
~HttpHeaderEntry();
static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
HttpHeaderEntry *clone() const;
int64_t getInt64() const;
Http::HdrType id;
- String name;
+ SBuf name;
String value;
};
void packInto(Packable * p, bool mask_sensitive_info=false) const;
HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
HttpHeaderEntry *findEntry(Http::HdrType id) const;
- int delByName(const char *name);
+ /// deletes all fields with a given name, if any.
+ /// \return #fields deleted
+ int delByName(const SBuf &name);
+ /// \deprecated use SBuf method instead. performance regression: reallocates
+ int delByName(const char *name) { return delByName(SBuf(name)); }
int delById(Http::HdrType id);
void delAt(HttpHeaderPos pos, int &headers_deleted);
void refreshMask();
String getByName(const SBuf &name) const;
String getByName(const char *name) const;
String getById(Http::HdrType id) const;
- /// sets value and returns true iff a [possibly empty] field identified by id is there
- bool getByIdIfPresent(Http::HdrType id, String &result) const;
- /// sets value and returns true iff a [possibly empty] named field is there
- bool getByNameIfPresent(const SBuf &s, String &value) const;
- bool getByNameIfPresent(const char *name, int namelen, String &value) const;
+ /// returns true iff a [possibly empty] field identified by id is there
+ /// when returning true, also sets the `result` parameter (if it is not nil)
+ bool getByIdIfPresent(Http::HdrType id, String *result) const;
+ /// returns true iff a [possibly empty] named field is there
+ /// when returning true, also sets the `value` parameter (if it is not nil)
+ bool hasNamed(const SBuf &s, String *value = 0) const;
+ /// \deprecated use SBuf method instead.
+ bool hasNamed(const char *name, unsigned int namelen, String *value = 0) const;
String getByNameListMember(const char *name, const char *member, const char separator) const;
String getListMember(Http::HdrType id, const char *member, const char separator) const;
int has(Http::HdrType id) const;
+ /// Appends "this cache" information to VIA header field.
+ /// Takes the initial VIA value from "from" parameter, if provided.
+ void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from = 0);
void putInt(Http::HdrType id, int number);
void putInt64(Http::HdrType id, int64_t number);
void putTime(Http::HdrType id, time_t htime);