]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Handle invalid/unsupported HTTP/X.X versions at parsing version label
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 5 Jan 2014 21:15:23 +0000 (13:15 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 5 Jan 2014 21:15:23 +0000 (13:15 -0800)
There is no need to duplicate the error response client-streams setup.
invalid-version and unsupported-version differ only in error page
displayed and the invalid-version page was supposed to be the same as
unsupported-version anyway.

src/client_side.cc
src/http/Http1Parser.cc

index 8e14db0f9229c0e0b6af98a8a186d42d18c5d567..5b6ab45b6badcf1214cf041190136fce3a0e5d18 100644 (file)
@@ -2566,12 +2566,17 @@ clientProcessRequest(ConnStateData *conn, Http1::RequestParser &hp, ClientSocket
         assert (repContext);
         switch (hp.request_parse_status) {
         case Http::scHeaderTooLarge:
-            repContext->setReplyToError(ERR_TOO_BIG, Http::scBadRequest, method, http->uri, conn->clientConnection->remote, NULL, conn->in.buf, NULL);
+            repContext->setReplyToError(ERR_TOO_BIG, Http::scBadRequest, method, http->uri,
+                                        conn->clientConnection->remote, NULL, conn->in.buf, NULL);
             break;
         case Http::scMethodNotAllowed:
             repContext->setReplyToError(ERR_UNSUP_REQ, Http::scMethodNotAllowed, method, http->uri,
                                         conn->clientConnection->remote, NULL, conn->in.buf, NULL);
             break;
+        case Http::scHttpVersionNotSupported:
+            repContext->setReplyToError(ERR_UNSUP_HTTPVERSION, Http::scHttpVersionNotSupported, method, http->uri,
+                                        conn->clientConnection->remote, NULL, conn->in.buf, NULL);
+            break;
         default:
             repContext->setReplyToError(ERR_INVALID_REQ, hp.request_parse_status, method, http->uri,
                                         conn->clientConnection->remote, NULL, conn->in.buf, NULL);
@@ -2595,25 +2600,6 @@ clientProcessRequest(ConnStateData *conn, Http1::RequestParser &hp, ClientSocket
         goto finish;
     }
 
-    /* RFC 2616 section 10.5.6 : handle unsupported HTTP major versions cleanly. */
-    /* We currently only support 0.9, 1.0, 1.1 properly */
-    if ( (http_ver.major == 0 && http_ver.minor != 9) ||
-            (http_ver.major > 1) ) {
-
-        clientStreamNode *node = context->getClientReplyContext();
-        debugs(33, 5, "Unsupported HTTP version discovered. :\n" << hp.messageProtocol());
-        conn->quitAfterError(request.getRaw());
-        // setLogUri should called before repContext->setReplyToError
-        setLogUri(http, http->uri,  true);
-        clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
-        assert (repContext);
-        repContext->setReplyToError(ERR_UNSUP_HTTPVERSION, Http::scHttpVersionNotSupported, method, http->uri,
-                                    conn->clientConnection->remote, NULL, hp.rawHeaderBuf(), NULL);
-        assert(context->http->out.offset == 0);
-        context->pullData();
-        goto finish;
-    }
-
     /* compile headers */
     if (http_ver.major >= 1 && !request->parseHeader(hp.rawHeaderBuf(), hp.headerBlockSize())) {
         clientStreamNode *node = context->getClientReplyContext();
index ff5c84276d94cb7ad6c5712176ecbb1902926afd..e3dfc2b1234d1143aacfad6c777ec1e8384d6df3 100644 (file)
@@ -366,6 +366,13 @@ Http1::RequestParser::parseRequestFirstLine()
     }
     msgProtocol_.minor = min;
 
+    /* RFC 2616 section 10.5.6 : handle unsupported HTTP major versions cleanly. */
+    /* We currently only support 0.9, 1.0, 1.1 properly in this parser */
+    if ((maj == 0 && min != 9) || (maj > 1)) {
+        request_parse_status = Http::scHttpVersionNotSupported;
+        return -1;
+    }
+
     /*
      * Rightio - we have all the schtuff. Return true; we've got enough.
      */