... resolving Via header truncation at 1024 bytes.
Also fixes the generated Via values for non-HTTP protocols.
#include "mime_header.h"
#include "profiler/Profiler.h"
#include "rfc1123.h"
+#include "sbuf/StringConvert.h"
#include "SquidConfig.h"
#include "StatHist.h"
#include "Store.h"
return CBIT_TEST(mask, id);
}
+void
+HttpHeader::addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from)
+{
+ // TODO: do not add Via header for messages where Squid itself
+ // generated the message (i.e., Downloader or ESI) there should be no Via header added at all.
+
+ if (Config.onoff.via) {
+ SBuf buf;
+ // RFC 7230 section 5.7.1.: protocol-name is omitted when
+ // the received protocol is HTTP.
+ if (ver.protocol > AnyP::PROTO_NONE && ver.protocol < AnyP::PROTO_UNKNOWN &&
+ ver.protocol != AnyP::PROTO_HTTP && ver.protocol != AnyP::PROTO_HTTPS)
+ buf.appendf("%s/", AnyP::ProtocolType_str[ver.protocol]);
+ buf.appendf("%d.%d %s", ver.major, ver.minor, ThisCache);
+ const HttpHeader *hdr = from ? from : this;
+ SBuf strVia = StringToSBuf(hdr->getList(Http::HdrType::VIA));
+ if (!strVia.isEmpty())
+ strVia.append(", ", 2);
+ strVia.append(buf);
+ // XXX: putStr() still suffers from String size limits
+ Must(strVia.length() < String::SizeMaxXXX());
+ delById(Http::HdrType::VIA);
+ putStr(Http::HdrType::VIA, strVia.c_str());
+ }
+}
+
void
HttpHeader::putInt(Http::HdrType id, int number)
{
#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 */
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);
return buf_[aPos];
}
+ /// The absolute size limit on data held in a String.
+ /// Since Strings can be nil-terminated implicitly it is best to ensure
+ /// the useful content length is strictly less than this limit.
+ static const size_type SizeMaxXXX() { return SizeMax_; }
+
size_type size() const { return len_; }
/// variant of size() suited to be used for printf-alikes.
hdr->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
}
- /* Append VIA */
- if (Config.onoff.via) {
- LOCAL_ARRAY(char, bbuf, MAX_URL + 32);
- String strVia;
- hdr->getList(Http::HdrType::VIA, &strVia);
- snprintf(bbuf, MAX_URL + 32, "%d.%d %s",
- reply->sline.version.major,
- reply->sline.version.minor,
- ThisCache);
- strListAdd(&strVia, bbuf, ',');
- hdr->delById(Http::HdrType::VIA);
- hdr->putStr(Http::HdrType::VIA, strVia.termedBuf());
- }
+ hdr->addVia(reply->sline.version);
+
/* Signal keep-alive or close explicitly */
hdr->putStr(Http::HdrType::CONNECTION, request->flags.proxyKeepalive ? "keep-alive" : "close");
request->flags.isRanged = false;
}
- /* append Via */
- if (Config.onoff.via) {
- String strVia;
- strVia = hdr_in->getList(Http::HdrType::VIA);
- snprintf(bbuf, BBUF_SZ, "%d.%d %s",
- request->http_ver.major,
- request->http_ver.minor, ThisCache);
- strListAdd(&strVia, bbuf, ',');
- hdr_out->putStr(Http::HdrType::VIA, strVia.termedBuf());
- strVia.clean();
- }
+ hdr_out->addVia(request->http_ver, hdr_in);
if (request->flags.accelerated) {
/* Append Surrogate-Capabilities */