From: Amos Jeffries Date: Fri, 3 Sep 2010 05:20:26 +0000 (-0600) Subject: Author: Alex Rousskov X-Git-Tag: SQUID_3_1_8~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d79d92836ecad55955012dbf37a801345470dd0;p=thirdparty%2Fsquid.git Author: Alex Rousskov HTTP/1.1: handle HTTP OPTIONS and TRACE requests with asterisk URIs. Handle '*' URIs in urlParse(). This allows Squid properly respond to OPTIONS and TRACE requests with '*' URIs and Max-Forwards value of zero. Forwarding such requests is out of this change scope and still does not work because the upstream host and port are not set. Co-Advisor test cases: test_case/rfc2616/options-bodyless-asterisk test_case/rfc2616/maxForwardsZero-OPTIONS-asterisk test_case/rfc2616/maxForwardsZero-TRACE-asterisk --- diff --git a/src/url.cc b/src/url.cc index d862fdad3f..1b801152fa 100644 --- a/src/url.cc +++ b/src/url.cc @@ -38,6 +38,13 @@ #include "URLScheme.h" #include "rfc1738.h" +static HttpRequest *urlParseFinish(const HttpRequestMethod& method, + const protocol_t protocol, + const char *const urlpath, + const char *const host, + const char *const login, + const int port, + HttpRequest *request); static HttpRequest *urnParse(const HttpRequestMethod& method, char *urn); static const char valid_hostname_chars_u[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -222,6 +229,11 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request) if (sscanf(url, "%[^:]:%d", host, &port) < 1) return NULL; + } else if ((method == METHOD_OPTIONS || method == METHOD_TRACE) && + strcmp(url, "*") == 0) { + protocol = PROTO_HTTP; + port = urlDefaultPort(protocol); + return urlParseFinish(method, protocol, url, host, login, port, request); } else if (!strncmp(url, "urn:", 4)) { return urnParse(method, url); } else { @@ -402,6 +414,23 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request) } } + return urlParseFinish(method, protocol, urlpath, host, login, port, request); +} + +/** + * Update request with parsed URI data. If the request arg is + * non-NULL, put parsed values there instead of allocating a new + * HttpRequest. + */ +static HttpRequest * +urlParseFinish(const HttpRequestMethod& method, + const protocol_t protocol, + const char *const urlpath, + const char *const host, + const char *const login, + const int port, + HttpRequest *request) +{ if (NULL == request) request = new HttpRequest(method, protocol, urlpath); else { @@ -767,8 +796,10 @@ urlCheckRequest(const HttpRequest * r) if (r->method == METHOD_CONNECT) return 1; - if (r->method == METHOD_TRACE) - return 1; + // we support OPTIONS and TRACE directed at us (with a 501 reply, for now) + // we also support forwarding OPTIONS and TRACE, except for the *-URI ones + if (r->method == METHOD_OPTIONS || r->method == METHOD_TRACE) + return (r->max_forwards == 0 || r->urlpath != "*"); if (r->method == METHOD_PURGE) return 1;