static void
purgeEntriesByHeader(const HttpRequest *req, const char *reqUrl, HttpMsg *rep, http_hdr_type hdr)
{
- const char *url, *absUrl;
+ const char *hdrUrl, *absUrl;
- if ((url = rep->header.getStr(hdr)) != NULL) {
- absUrl = urlAbsolute(req, url);
+ if ((hdrUrl = rep->header.getStr(hdr)) != NULL) {
+ absUrl = urlMakeAbsolute(req, hdrUrl);
if (absUrl != NULL) {
- url = absUrl;
+ hdrUrl = absUrl;
}
if (absUrl != NULL) { // if the URL was relative, it is by nature the same host
- purgeEntriesByUrl(url);
- } else if (sameUrlHosts(reqUrl, url)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph
- purgeEntriesByUrl(url);
+ purgeEntriesByUrl(hdrUrl);
+ } else if (sameUrlHosts(reqUrl, hdrUrl)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph
+ purgeEntriesByUrl(hdrUrl);
}
if (absUrl != NULL) {
safe_free(absUrl);
SQUIDCEXTERN void urlInitialize(void);
SQUIDCEXTERN HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL);
SQUIDCEXTERN const char *urlCanonical(HttpRequest *);
-SQUIDCEXTERN const char *urlAbsolute(const HttpRequest *, const char *);
+SQUIDCEXTERN int urlIsRelative(const char *);
+SQUIDCEXTERN const char *urlMakeAbsolute(const HttpRequest *, const char *);
SQUIDCEXTERN char *urlRInternal(const char *host, u_short port, const char *dir, const char *name);
SQUIDCEXTERN char *urlInternal(const char *dir, const char *name);
SQUIDCEXTERN int matchDomainName(const char *host, const char *domain);
return buf;
}
+/*
+ * Test if a URL is relative.
+ *
+ * RFC 1808 says that colons can show up in 'fragments' or 'queries'.
+ * Fragments come after a '#' and queries come after '?'.
+ */
+int
+urlIsRelative(const char *url)
+{
+ const char *p;
+
+ if (url == NULL) {
+ return (0);
+ }
+ if (*url == '\0') {
+ return (0);
+ }
+
+ for (p = url; *p != '\0' && *p != ':' && *p != '#' && *p != '?'; p++);
+
+ if (*p == ':') {
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * Take a potentially relative URL. If the URL is _not_ relative, return NULL.
+ * If the URL is relative, generate an absolute URL based on the provided
+ * request.
+ */
const char *
-urlAbsolute(const HttpRequest * req, const char *relUrl)
+urlMakeAbsolute(const HttpRequest * req, const char *relUrl)
{
char *urlbuf;
const char *path, *last_slash;
size_t urllen, pathlen;
- if (relUrl == NULL) {
- return (NULL);
- }
if (req->method.id() == METHOD_CONNECT) {
return (NULL);
}
- if (strchr(relUrl, ':') != NULL) {
+ if (!urlIsRelative(relUrl)) {
return (NULL);
}
urlbuf = (char *)xmalloc(MAX_URL * sizeof(char));