/*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "http.h"
#include "http/one/ResponseParser.h"
#include "http/one/TeChunkedParser.h"
+#include "http/Stream.h"
#include "HttpControlMsg.h"
#include "HttpHdrCc.h"
#include "HttpHdrContRange.h"
static void httpMaybeRemovePublic(StoreEntry *, Http::StatusCode);
static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request,
HttpHeader * hdr_out, const int we_do_ranges, const HttpStateFlags &);
-//Declared in HttpHeaderTools.cc
-void httpHdrAdd(HttpHeader *heads, HttpRequest *request, const AccessLogEntryPointer &al, HeaderWithAclList &headers_add);
HttpStateData::HttpStateData(FwdState *theFwdState) :
AsyncJob("HttpStateData"),
HttpStateData::httpStateConnClosed(const CommCloseCbParams ¶ms)
{
debugs(11, 5, "httpStateFree: FD " << params.fd << ", httpState=" << params.data);
+ doneWithFwd = "httpStateConnClosed()"; // assume FwdState is monitoring too
mustStop("HttpStateData::httpStateConnClosed");
}
fwd->fail(new ErrorState(ERR_READ_TIMEOUT, Http::scGatewayTimeout, fwd->request));
}
- serverConnection->close();
+ closeServer();
+ mustStop("HttpStateData::httpTimeout");
}
/// Remove an existing public store entry if the incoming response (to be
mayStore = true;
// HTTPbis pt6 section 3.2: a response CC:must-revalidate is present
- } else if (rep->cache_control->mustRevalidate() && !REFRESH_OVERRIDE(ignore_must_revalidate)) {
+ } else if (rep->cache_control->mustRevalidate()) {
debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:must-revalidate");
mayStore = true;
// HTTPbis WG verdict on this is that it is omitted from the spec due to being 'unexpected' by
// some. The caching+revalidate is not exactly unsafe though with Squids interpretation of no-cache
// (without parameters) as equivalent to must-revalidate in the reply.
- } else if (rep->cache_control->hasNoCache() && rep->cache_control->noCache().size() == 0 && !REFRESH_OVERRIDE(ignore_must_revalidate)) {
+ } else if (rep->cache_control->hasNoCache() && rep->cache_control->noCache().size() == 0) {
debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:no-cache (equivalent to must-revalidate)");
mayStore = true;
#endif
* continuous push replies. These are generally dynamic and
* probably should not be cachable
*/
- if ((v = hdr->getStr(HDR_CONTENT_TYPE)))
+ if ((v = hdr->getStr(Http::HdrType::CONTENT_TYPE)))
if (!strncasecmp(v, "multipart/x-mixed-replace", 25)) {
debugs(22, 3, HERE << "NO because Content-Type:multipart/x-mixed-replace");
return 0;
/* NOTREACHED */
}
-/*
- * For Vary, store the relevant request headers as
- * virtual headers in the reply
- * Returns false if the variance cannot be stored
- */
-const char *
-httpMakeVaryMark(HttpRequest * request, HttpReply const * reply)
+/// assemble a variant key (vary-mark) from the given Vary header and HTTP request
+static void
+assembleVaryKey(String &vary, SBuf &vstr, const HttpRequest &request)
{
- String vary, hdr;
- const char *pos = NULL;
- const char *item;
- const char *value;
- int ilen;
- static String vstr;
-
- vstr.clean();
- vary = reply->header.getList(HDR_VARY);
+ static const SBuf asterisk("*");
+ const char *pos = nullptr;
+ const char *item = nullptr;
+ int ilen = 0;
while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
- char *name = (char *)xmalloc(ilen + 1);
- xstrncpy(name, item, ilen + 1);
- Tolower(name);
-
- if (strcmp(name, "*") == 0) {
- /* Can not handle "Vary: *" withtout ETag support */
- safe_free(name);
- vstr.clean();
+ SBuf name(item, ilen);
+ if (name == asterisk) {
+ vstr.clear();
break;
}
-
- strListAdd(&vstr, name, ',');
- hdr = request->header.getByName(name);
- safe_free(name);
- value = hdr.termedBuf();
-
+ name.toLower();
+ if (!vstr.isEmpty())
+ vstr.append(", ", 2);
+ vstr.append(name);
+ String hdr(request.header.getByName(name));
+ const char *value = hdr.termedBuf();
if (value) {
value = rfc1738_escape_part(value);
vstr.append("=\"", 2);
hdr.clean();
}
+}
- vary.clean();
-#if X_ACCELERATOR_VARY
-
- pos = NULL;
- vary = reply->header.getList(HDR_X_ACCELERATOR_VARY);
-
- while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
- char *name = (char *)xmalloc(ilen + 1);
- xstrncpy(name, item, ilen + 1);
- Tolower(name);
- strListAdd(&vstr, name, ',');
- hdr = request->header.getByName(name);
- safe_free(name);
- value = hdr.termedBuf();
-
- if (value) {
- value = rfc1738_escape_part(value);
- vstr.append("=\"", 2);
- vstr.append(value);
- vstr.append("\"", 1);
- }
+/*
+ * For Vary, store the relevant request headers as
+ * virtual headers in the reply
+ * Returns an empty SBuf if the variance cannot be stored
+ */
+SBuf
+httpMakeVaryMark(HttpRequest * request, HttpReply const * reply)
+{
+ SBuf vstr;
+ String vary;
- hdr.clean();
- }
+ vary = reply->header.getList(Http::HdrType::VARY);
+ assembleVaryKey(vary, vstr, *request);
+#if X_ACCELERATOR_VARY
vary.clean();
+ vary = reply->header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY);
+ assembleVaryKey(vary, vstr, *request);
#endif
- debugs(11, 3, "httpMakeVaryMark: " << vstr);
- return vstr.termedBuf();
+ debugs(11, 3, vstr);
+ return vstr;
}
void
}
}
- flags.headers_parsed = true;
-
if (!parsedOk) {
// unrecoverable parsing error
+ // TODO: Use Raw! XXX: inBuf no longer has the [beginning of the] malformed header.
debugs(11, 3, "Non-HTTP-compliant header:\n---------\n" << inBuf << "\n----------");
+ flags.headers_parsed = true;
HttpReply *newrep = new HttpReply;
- newrep->sline.set(Http::ProtocolVersion(), hp->messageStatus());
- HttpReply *vrep = setVirginReply(newrep);
- entry->replaceHttpReply(vrep);
- // XXX: close the server connection ?
+ newrep->sline.set(Http::ProtocolVersion(), hp->parseStatusCode);
+ setVirginReply(newrep);
ctx_exit(ctx);
return;
}
newrep->sline.version.minor = hp->messageProtocol().minor;
// parse headers
- newrep->pstate = psReadyToParseHeaders;
- if (newrep->httpMsgParseStep(hp->mimeHeader().rawContent(), hp->mimeHeader().length(), true) < 0) {
+ if (!newrep->parseHeader(*hp)) {
// XXX: when Http::ProtocolVersion is a function, remove this hack. just set with messageProtocol()
newrep->sline.set(Http::ProtocolVersion(), Http::scInvalidHeader);
newrep->sline.version.protocol = hp->messageProtocol().protocol;
// done with Parser, now process using the HttpReply
hp = NULL;
+ newrep->sources |= request->url.getScheme() == AnyP::PROTO_HTTPS ? HttpMsg::srcHttps : HttpMsg::srcHttp;
+
newrep->removeStaleWarnings();
if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->sline.status() >= 100 && newrep->sline.status() < 200) {
reply and has in its list the "Session-Based-Authentication"
which means that the peer supports connection pinning.
*/
- if (!hdr->has(HDR_PROXY_SUPPORT))
+ if (!hdr->has(Http::HdrType::PROXY_SUPPORT))
return false;
- header = hdr->getStrOrList(HDR_PROXY_SUPPORT);
+ header = hdr->getStrOrList(Http::HdrType::PROXY_SUPPORT);
/* XXX This ought to be done in a case-insensitive manner */
rc = (strstr(header.termedBuf(), "Session-Based-Authentication") != NULL);
httpMaybeRemovePublic(entry, rep->sline.status());
bool varyFailure = false;
- if (rep->header.has(HDR_VARY)
+ if (rep->header.has(Http::HdrType::VARY)
#if X_ACCELERATOR_VARY
- || rep->header.has(HDR_X_ACCELERATOR_VARY)
+ || rep->header.has(Http::HdrType::HDR_X_ACCELERATOR_VARY)
#endif
) {
- const char *vary = httpMakeVaryMark(request, rep);
+ const SBuf vary(httpMakeVaryMark(request, rep));
- if (!vary) {
+ if (vary.isEmpty()) {
entry->makePrivate();
if (!fwd->reforwardableStatus(rep->sline.status()))
EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
varyFailure = true;
} else {
- entry->mem_obj->vary_headers = xstrdup(vary);
+ entry->mem_obj->vary_headers = vary;
}
}
/* HACK: Pragma: no-cache in _replies_ is not documented in HTTP,
* but servers like "Active Imaging Webcast/2.0" sure do use it */
- if (rep->header.has(HDR_PRAGMA) &&
- rep->header.hasListMember(HDR_PRAGMA,"no-cache",','))
+ if (rep->header.has(Http::HdrType::PRAGMA) &&
+ rep->header.hasListMember(Http::HdrType::PRAGMA,"no-cache",','))
EBIT_SET(entry->flags, ENTRY_REVALIDATE);
}
#endif
delayId.bytesIn(rd.size);
#endif
- kb_incr(&(statCounter.server.all.kbytes_in), rd.size);
- kb_incr(&(statCounter.server.http.kbytes_in), rd.size);
+ statCounter.server.all.kbytes_in += rd.size;
+ statCounter.server.http.kbytes_in += rd.size;
++ IOStats.Http.reads;
int bin = 0;
err->xerrno = rd.xerrno;
fwd->fail(err);
flags.do_next_read = false;
- io.conn->close();
-
+ closeServer();
+ mustStop("HttpStateData::readReply");
return;
}
const Http::StatusCode s = vrep->sline.status();
const AnyP::ProtocolVersion &v = vrep->sline.version;
if (s == Http::scInvalidHeader && v != Http::ProtocolVersion(0,9)) {
- debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->url.host() << request->urlpath.termedBuf());
+ debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->url);
error = ERR_INVALID_RESP;
} else if (s == Http::scHeaderTooLarge) {
fwd->dontRetry(true);
error = ERR_TOO_BIG;
+ } else if (vrep->header.conflictingContentLength()) {
+ fwd->dontRetry(true);
+ error = ERR_INVALID_RESP;
} else {
return true; // done parsing, got reply, and no error
}
} else {
// parsed headers but got no reply
- debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: No reply at all for " << entry->url() << " AKA " << request->url.host() << request->urlpath.termedBuf());
+ debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: No reply at all for " << entry->url() << " AKA " << request->url);
error = ERR_INVALID_RESP;
}
} else {
assert(eof);
if (inBuf.length()) {
error = ERR_INVALID_RESP;
- debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry->url() << " AKA " << request->url.host() << request->urlpath.termedBuf());
+ debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry->url() << " AKA " << request->url);
} else {
error = ERR_ZERO_SIZE_OBJECT;
- debugs(11, (request->flags.accelerated?DBG_IMPORTANT:2), "WARNING: HTTP: Invalid Response: No object data received for " <<
- entry->url() << " AKA " << request->url.host() << request->urlpath.termedBuf());
+ debugs(11, (request->flags.accelerated?DBG_IMPORTANT:2), "WARNING: HTTP: Invalid Response: No object data received for " << entry->url() << " AKA " << request->url);
}
}
entry->reset();
fwd->fail(new ErrorState(error, Http::scBadGateway, fwd->request));
flags.do_next_read = false;
- serverConnection->close();
+ closeServer();
+ mustStop("HttpStateData::continueAfterParsingHeader");
return false; // quit on error
}
writeReplyBody();
}
+ // storing/sending methods like earlier adaptOrFinalizeReply() or
+ // above writeReplyBody() may release/abort the store entry.
if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
- // The above writeReplyBody() call may have aborted the store entry.
+ // TODO: In some cases (e.g., 304), we should keep persistent conn open.
+ // Detect end-of-reply (and, hence, pool our idle pconn) earlier (ASAP).
abortTransaction("store entry aborted while storing reply");
return;
} else
if (io.size > 0) {
fd_bytes(io.fd, io.size, FD_WRITE);
- kb_incr(&(statCounter.server.all.kbytes_out), io.size);
- kb_incr(&(statCounter.server.http.kbytes_out), io.size);
+ statCounter.server.all.kbytes_out += io.size;
+ statCounter.server.http.kbytes_out += io.size;
}
if (io.flag == Comm::ERR_CLOSING)
ErrorState *err = new ErrorState(ERR_WRITE_ERROR, Http::scBadGateway, fwd->request);
err->xerrno = io.xerrno;
fwd->fail(err);
- serverConnection->close();
+ closeServer();
+ mustStop("HttpStateData::wroteLast");
return;
}
request->hier.peer_http_request_sent = current_time;
}
-// Close the HTTP server connection. Used by serverComplete().
void
HttpStateData::closeServer()
{
static void
httpFixupAuthentication(HttpRequest * request, const HttpHeader * hdr_in, HttpHeader * hdr_out, const HttpStateFlags &flags)
{
- http_hdr_type header = flags.originpeer ? HDR_AUTHORIZATION : HDR_PROXY_AUTHORIZATION;
+ Http::HdrType header = flags.originpeer ? Http::HdrType::AUTHORIZATION : Http::HdrType::PROXY_AUTHORIZATION;
/* Nothing to do unless we are forwarding to a peer */
if (!request->flags.proxying)
return;
/* PROXYPASS is a special case, single-signon to servers with the proxy password (basic only) */
- if (flags.originpeer && strcmp(request->peer_login, "PROXYPASS") == 0 && hdr_in->has(HDR_PROXY_AUTHORIZATION)) {
- const char *auth = hdr_in->getStr(HDR_PROXY_AUTHORIZATION);
+ if (flags.originpeer && strcmp(request->peer_login, "PROXYPASS") == 0 && hdr_in->has(Http::HdrType::PROXY_AUTHORIZATION)) {
+ const char *auth = hdr_in->getStr(Http::HdrType::PROXY_AUTHORIZATION);
if (auth && strncasecmp(auth, "basic ", 6) == 0) {
hdr_out->putStr(header, auth);
if (strncmp(request->peer_login, "NEGOTIATE",strlen("NEGOTIATE")) == 0) {
char *Token=NULL;
char *PrincipalName=NULL,*p;
+ int negotiate_flags = 0;
+
if ((p=strchr(request->peer_login,':')) != NULL ) {
PrincipalName=++p;
}
- Token = peer_proxy_negotiate_auth(PrincipalName, request->peer_host);
+ if (request->flags.auth_no_keytab) {
+ negotiate_flags |= PEER_PROXY_NEGOTIATE_NOKEYTAB;
+ }
+ Token = peer_proxy_negotiate_auth(PrincipalName, request->peer_host, negotiate_flags);
if (Token) {
httpHeaderPutStrf(hdr_out, header, "Negotiate %s",Token);
}
/* use our IMS header if the cached entry has Last-Modified time */
if (request->lastmod > -1)
- hdr_out->putTime(HDR_IF_MODIFIED_SINCE, request->lastmod);
+ hdr_out->putTime(Http::HdrType::IF_MODIFIED_SINCE, request->lastmod);
// Add our own If-None-Match field if the cached entry has a strong ETag.
// copyOneHeaderFromClientsideRequestToUpstreamRequest() adds client ones.
if (request->etag.size() > 0) {
- hdr_out->addEntry(new HttpHeaderEntry(HDR_IF_NONE_MATCH, NULL,
+ hdr_out->addEntry(new HttpHeaderEntry(Http::HdrType::IF_NONE_MATCH, NULL,
request->etag.termedBuf()));
}
bool we_do_ranges = decideIfWeDoRanges (request);
- String strConnection (hdr_in->getList(HDR_CONNECTION));
+ String strConnection (hdr_in->getList(Http::HdrType::CONNECTION));
while ((e = hdr_in->getEntry(&pos)))
copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, hdr_out, we_do_ranges, flags);
/* append Via */
if (Config.onoff.via) {
String strVia;
- strVia = hdr_in->getList(HDR_VIA);
+ 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(HDR_VIA, strVia.termedBuf());
+ hdr_out->putStr(Http::HdrType::VIA, strVia.termedBuf());
strVia.clean();
}
if (request->flags.accelerated) {
/* Append Surrogate-Capabilities */
- String strSurrogate(hdr_in->getList(HDR_SURROGATE_CAPABILITY));
+ String strSurrogate(hdr_in->getList(Http::HdrType::SURROGATE_CAPABILITY));
#if USE_SQUID_ESI
snprintf(bbuf, BBUF_SZ, "%s=\"Surrogate/1.0 ESI/1.0\"", Config.Accel.surrogate_id);
#else
snprintf(bbuf, BBUF_SZ, "%s=\"Surrogate/1.0\"", Config.Accel.surrogate_id);
#endif
strListAdd(&strSurrogate, bbuf, ',');
- hdr_out->putStr(HDR_SURROGATE_CAPABILITY, strSurrogate.termedBuf());
+ hdr_out->putStr(Http::HdrType::SURROGATE_CAPABILITY, strSurrogate.termedBuf());
}
/** \pre Handle X-Forwarded-For */
if (strcmp(opt_forwarded_for, "delete") != 0) {
- String strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
+ String strFwd = hdr_in->getList(Http::HdrType::X_FORWARDED_FOR);
- if (strFwd.size() > 65536/2) {
+ // if we cannot double strFwd size, then it grew past 50% of the limit
+ if (!strFwd.canGrowBy(strFwd.size())) {
// There is probably a forwarding loop with Via detection disabled.
// If we do nothing, String will assert on overflow soon.
// TODO: Terminate all transactions with huge XFF?
static int warnedCount = 0;
if (warnedCount++ < 100) {
- const char *url = entry ? entry->url() : urlCanonical(request);
+ const SBuf url(entry ? SBuf(entry->url()) : request->effectiveRequestUri());
debugs(11, DBG_IMPORTANT, "Warning: likely forwarding loop with " << url);
}
}
strFwd = request->client_addr.toStr(ntoabuf, MAX_IPSTRLEN);
}
if (strFwd.size() > 0)
- hdr_out->putStr(HDR_X_FORWARDED_FOR, strFwd.termedBuf());
+ hdr_out->putStr(Http::HdrType::X_FORWARDED_FOR, strFwd.termedBuf());
}
/** If set to DELETE - do not copy through. */
/* append Host if not there already */
- if (!hdr_out->has(HDR_HOST)) {
+ if (!hdr_out->has(Http::HdrType::HOST)) {
if (request->peer_domain) {
- hdr_out->putStr(HDR_HOST, request->peer_domain);
+ hdr_out->putStr(Http::HdrType::HOST, request->peer_domain);
} else {
SBuf authority = request->url.authority();
- hdr_out->putStr(HDR_HOST, authority.c_str());
+ hdr_out->putStr(Http::HdrType::HOST, authority.c_str());
}
}
/* append Authorization if known in URL, not in header and going direct */
- if (!hdr_out->has(HDR_AUTHORIZATION)) {
+ if (!hdr_out->has(Http::HdrType::AUTHORIZATION)) {
if (!request->flags.proxying && !request->url.userInfo().isEmpty()) {
static uint8_t result[base64_encode_len(MAX_URL*2)]; // should be big enough for a single URI segment
struct base64_encode_ctx ctx;
blen += base64_encode_final(&ctx, result+blen);
result[blen] = '\0';
if (blen)
- httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %.*s", (int)blen, result);
+ httpHeaderPutStrf(hdr_out, Http::HdrType::AUTHORIZATION, "Basic %.*s", (int)blen, result);
}
}
#if 0 /* see bug 2330 */
/* Set no-cache if determined needed but not found */
if (request->flags.nocache)
- EBIT_SET(cc->mask, CC_NO_CACHE);
+ EBIT_SET(cc->mask, HttpHdrCcType::CC_NO_CACHE);
#endif
/* Add max-age only without no-cache */
if (!cc->hasMaxAge() && !cc->hasNoCache()) {
- const char *url =
- entry ? entry->url() : urlCanonical(request);
- cc->maxAge(getMaxAge(url));
-
+ // XXX: performance regression. c_str() reallocates
+ SBuf tmp(request->effectiveRequestUri());
+ cc->maxAge(getMaxAge(entry ? entry->url() : tmp.c_str()));
}
/* Enforce sibling relations */
/* maybe append Connection: keep-alive */
if (flags.keepalive) {
- hdr_out->putStr(HDR_CONNECTION, "keep-alive");
+ hdr_out->putStr(Http::HdrType::CONNECTION, "keep-alive");
}
/* append Front-End-Https */
if (flags.front_end_https) {
if (flags.front_end_https == 1 || request->url.getScheme() == AnyP::PROTO_HTTPS)
- hdr_out->putStr(HDR_FRONT_END_HTTPS, "On");
+ hdr_out->putStr(Http::HdrType::FRONT_END_HTTPS, "On");
}
if (flags.chunked_request) {
// Do not just copy the original value so that if the client-side
// starts decode other encodings, this code may remain valid.
- hdr_out->putStr(HDR_TRANSFER_ENCODING, "chunked");
+ hdr_out->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
}
/* Now mangle the headers. */
- if (Config2.onoff.mangle_request_headers)
- httpHdrMangleList(hdr_out, request, ROR_REQUEST);
-
- if (Config.request_header_add && !Config.request_header_add->empty())
- httpHdrAdd(hdr_out, request, al, *Config.request_header_add);
+ httpHdrMangleList(hdr_out, request, al, ROR_REQUEST);
strConnection.clean();
}
/** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid should not pass on. */
- case HDR_PROXY_AUTHORIZATION:
+ case Http::HdrType::PROXY_AUTHORIZATION:
/** \par Proxy-Authorization:
* Only pass on proxy authentication to peers for which
* authentication forwarding is explicitly enabled
/** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid does not pass on. */
- case HDR_CONNECTION: /** \par Connection: */
- case HDR_TE: /** \par TE: */
- case HDR_KEEP_ALIVE: /** \par Keep-Alive: */
- case HDR_PROXY_AUTHENTICATE: /** \par Proxy-Authenticate: */
- case HDR_TRAILER: /** \par Trailer: */
- case HDR_UPGRADE: /** \par Upgrade: */
- case HDR_TRANSFER_ENCODING: /** \par Transfer-Encoding: */
+ case Http::HdrType::CONNECTION: /** \par Connection: */
+ case Http::HdrType::TE: /** \par TE: */
+ case Http::HdrType::KEEP_ALIVE: /** \par Keep-Alive: */
+ case Http::HdrType::PROXY_AUTHENTICATE: /** \par Proxy-Authenticate: */
+ case Http::HdrType::TRAILER: /** \par Trailer: */
+ case Http::HdrType::UPGRADE: /** \par Upgrade: */
+ case Http::HdrType::TRANSFER_ENCODING: /** \par Transfer-Encoding: */
break;
/** \par OTHER headers I haven't bothered to track down yet. */
- case HDR_AUTHORIZATION:
+ case Http::HdrType::AUTHORIZATION:
/** \par WWW-Authorization:
* Pass on WWW authentication */
break;
- case HDR_HOST:
+ case Http::HdrType::HOST:
/** \par Host:
* Normally Squid rewrites the Host: header.
* However, there is one case when we don't: If the URL
* 'redir_rewrites_host' to be off.
*/
if (request->peer_domain)
- hdr_out->putStr(HDR_HOST, request->peer_domain);
+ hdr_out->putStr(Http::HdrType::HOST, request->peer_domain);
else if (request->flags.redirected && !Config.onoff.redir_rewrites_host)
hdr_out->addEntry(e->clone());
else {
SBuf authority = request->url.authority();
- hdr_out->putStr(HDR_HOST, authority.c_str());
+ hdr_out->putStr(Http::HdrType::HOST, authority.c_str());
}
break;
- case HDR_IF_MODIFIED_SINCE:
+ case Http::HdrType::IF_MODIFIED_SINCE:
/** \par If-Modified-Since:
* append unless we added our own,
* but only if cache_miss_revalidate is enabled, or
* \note at most one client's If-Modified-Since header can pass through
*/
// XXX: need to check and cleanup the auth case so cacheable auth requests get cached.
- if (hdr_out->has(HDR_IF_MODIFIED_SINCE))
+ if (hdr_out->has(Http::HdrType::IF_MODIFIED_SINCE))
break;
else if (Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
hdr_out->addEntry(e->clone());
break;
- case HDR_IF_NONE_MATCH:
+ case Http::HdrType::IF_NONE_MATCH:
/** \par If-None-Match:
* append if the wildcard '*' special case value is present, or
* cache_miss_revalidate is disabled, or
* \note this header lists a set of responses for the server to elide sending. Squid added values are extending that set.
*/
// XXX: need to check and cleanup the auth case so cacheable auth requests get cached.
- if (hdr_out->hasListMember(HDR_IF_MATCH, "*", ',') || Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
+ if (hdr_out->hasListMember(Http::HdrType::IF_MATCH, "*", ',') || Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
hdr_out->addEntry(e->clone());
break;
- case HDR_MAX_FORWARDS:
+ case Http::HdrType::MAX_FORWARDS:
/** \par Max-Forwards:
* pass only on TRACE or OPTIONS requests */
if (request->method == Http::METHOD_TRACE || request->method == Http::METHOD_OPTIONS) {
const int64_t hops = e->getInt64();
if (hops > 0)
- hdr_out->putInt64(HDR_MAX_FORWARDS, hops - 1);
+ hdr_out->putInt64(Http::HdrType::MAX_FORWARDS, hops - 1);
}
break;
- case HDR_VIA:
+ case Http::HdrType::VIA:
/** \par Via:
* If Via is disabled then forward any received header as-is.
* Otherwise leave for explicit updated addition later. */
break;
- case HDR_RANGE:
+ case Http::HdrType::RANGE:
- case HDR_IF_RANGE:
+ case Http::HdrType::IF_RANGE:
- case HDR_REQUEST_RANGE:
+ case Http::HdrType::REQUEST_RANGE:
/** \par Range:, If-Range:, Request-Range:
* Only pass if we accept ranges */
if (!we_do_ranges)
break;
- case HDR_PROXY_CONNECTION: // SHOULD ignore. But doing so breaks things.
+ case Http::HdrType::PROXY_CONNECTION: // SHOULD ignore. But doing so breaks things.
break;
- case HDR_CONTENT_LENGTH:
+ case Http::HdrType::CONTENT_LENGTH:
// pass through unless we chunk; also, keeping this away from default
// prevents request smuggling via Connection: Content-Length tricks
if (!flags.chunked_request)
hdr_out->addEntry(e->clone());
break;
- case HDR_X_FORWARDED_FOR:
+ case Http::HdrType::X_FORWARDED_FOR:
- case HDR_CACHE_CONTROL:
+ case Http::HdrType::CACHE_CONTROL:
/** \par X-Forwarded-For:, Cache-Control:
* handled specially by Squid, so leave off for now.
* append these after the loop if needed */
break;
- case HDR_FRONT_END_HTTPS:
+ case Http::HdrType::FRONT_END_HTTPS:
/** \par Front-End-Https:
* Pass thru only if peer is configured with front-end-https */
if (!flags.front_end_https)
* not the one we are sending. Needs checking.
*/
const AnyP::ProtocolVersion httpver = Http::ProtocolVersion();
- const char * url;
- if (_peer && !_peer->options.originserver)
- url = urlCanonical(request);
- else
- url = request->urlpath.termedBuf();
- mb->appendf(SQUIDSBUFPH " %s %s/%d.%d\r\n",
+ const SBuf url(_peer && !_peer->options.originserver ? request->effectiveRequestUri() : request->url.path());
+ mb->appendf(SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\r\n",
SQUIDSBUFPRINT(request->method.image()),
- url && *url ? url : "/",
+ SQUIDSBUFPRINT(url),
AnyP::ProtocolType_str[httpver.protocol],
httpver.major,httpver.minor);
/* build and pack headers */
if (request->flags.pinned && request->flags.connectionAuth)
request->flags.authSent = true;
- else if (hdr.has(HDR_AUTHORIZATION))
+ else if (hdr.has(Http::HdrType::AUTHORIZATION))
request->flags.authSent = true;
hdr.packInto(mb);
debugs(11, DBG_IMPORTANT, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << request->client_addr << "' -> '" << entry->url() << "'" );
if (virginReply()->sline.status() == Http::scInvalidHeader) {
- serverConnection->close();
+ closeServer();
+ mustStop("HttpStateData::handleMoreRequestBodyAvailable");
return;
}
}
HttpStateData::sentRequestBody(const CommIoCbParams &io)
{
if (io.size > 0)
- kb_incr(&statCounter.server.http.kbytes_out, io.size);
+ statCounter.server.http.kbytes_out += io.size;
Client::sentRequestBody(io);
}
-// Quickly abort the transaction
-// TODO: destruction should be sufficient as the destructor should cleanup,
-// including canceling close handlers
void
-HttpStateData::abortTransaction(const char *reason)
+HttpStateData::abortAll(const char *reason)
{
debugs(11,5, HERE << "aborting transaction for " << reason <<
"; " << serverConnection << ", this " << this);
-
- if (Comm::IsConnOpen(serverConnection)) {
- serverConnection->close();
- return;
- }
-
- fwd->handleUnregisteredServerEnd();
- mustStop("HttpStateData::abortTransaction");
+ mustStop(reason);
}