/*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "HttpRequest.h"
#include "mgr/Registration.h"
#include "neighbors.h"
+#include "PeerSelectState.h"
#include "SquidConfig.h"
#include "Store.h"
-#include "URL.h"
#include <cmath>
}
CachePeer *
-carpSelectParent(HttpRequest * request)
+carpSelectParent(PeerSelector *ps)
{
+ assert(ps);
+ HttpRequest *request = ps->request;
+
int k;
CachePeer *p = NULL;
CachePeer *tp;
return NULL;
/* calculate hash key */
- debugs(39, 2, "carpSelectParent: Calculating hash for " << urlCanonical(request));
+ debugs(39, 2, "carpSelectParent: Calculating hash for " << request->effectiveRequestUri());
/* select CachePeer */
for (k = 0; k < n_carp_peers; ++k) {
SBuf key;
tp = carp_peers[k];
if (tp->options.carp_key.set) {
- //this code follows urlCanonical's pattern.
- // corner cases should use the canonical URL
+ // this code follows URI syntax pattern.
+ // corner cases should use the full effective request URI
if (tp->options.carp_key.scheme) {
- key.append(request->url.getScheme().c_str());
+ key.append(request->url.getScheme().image());
if (key.length()) //if the scheme is not empty
key.append("://");
}
if (tp->options.carp_key.host) {
- key.append(request->GetHost());
+ key.append(request->url.host());
}
if (tp->options.carp_key.port) {
- key.appendf(":%d", request->port);
+ key.appendf(":%u", request->url.port());
}
if (tp->options.carp_key.path) {
- String::size_type pos;
- if ((pos=request->urlpath.find('?'))!=String::npos)
- key.append(SBuf(request->urlpath.substr(0,pos)));
- else
- key.append(SBuf(request->urlpath));
+ // XXX: fix when path and query are separate
+ key.append(request->url.path().substr(0,request->url.path().find('?'))); // 0..N
}
if (tp->options.carp_key.params) {
- String::size_type pos;
- if ((pos=request->urlpath.find('?'))!=String::npos)
- key.append(SBuf(request->urlpath.substr(pos,request->urlpath.size())));
+ // XXX: fix when path and query are separate
+ SBuf::size_type pos;
+ if ((pos=request->url.path().find('?')) != SBuf::npos)
+ key.append(request->url.path().substr(pos)); // N..npos
}
}
// if the url-based key is empty, e.g. because the user is
// asking to balance on the path but the request doesn't supply any,
- // then fall back to canonical URL
+ // then fall back to the effective request URI
if (key.isEmpty())
- key=SBuf(urlCanonical(request));
+ key=request->effectiveRequestUri();
for (const char *c = key.rawContent(), *e=key.rawContent()+key.length(); c < e; ++c)
user_hash += ROTATE_LEFT(user_hash, 19) + *c;
debugs(39, 3, "carpSelectParent: key=" << key << " name=" << tp->name << " combined_hash=" << combined_hash <<
" score=" << std::setprecision(0) << score);
- if ((score > high_score) && peerHTTPOkay(tp, request)) {
+ if ((score > high_score) && peerHTTPOkay(tp, ps)) {
p = tp;
high_score = score;
}