Bug 632061 - Firefox 4 does not always properly handle HTTP/0.9 responses r=bz a=blocking-2.0
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 08 Feb 2011 18:26:33 -0500
changeset 62188 3872a1e4a8811c41dd444cdeed36e62b7a393b04
parent 62187 ca548ef9d8c653adddc82177befb141e27c8c35f
child 62189 682d008059c6740065fa388be1fe0ac47207cc4d
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersbz, blocking-2
bugs632061
milestone2.0b12pre
Bug 632061 - Firefox 4 does not always properly handle HTTP/0.9 responses r=bz a=blocking-2.0
netwerk/protocol/http/nsHttpTransaction.cpp
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -682,16 +682,19 @@ nsHttpTransaction::Restart()
 char *
 nsHttpTransaction::LocateHttpStart(char *buf, PRUint32 len,
                                    PRBool aAllowPartialMatch)
 {
     NS_ASSERTION(!aAllowPartialMatch || mLineBuf.IsEmpty(), "ouch");
 
     static const char HTTPHeader[] = "HTTP/1.";
     static const PRInt32 HTTPHeaderLen = sizeof(HTTPHeader) - 1;
+    
+    if (aAllowPartialMatch && (len < HTTPHeaderLen))
+        return (PL_strncasecmp(buf, HTTPHeader, len) == 0) ? buf : nsnull;
 
     // mLineBuf can contain partial match from previous search
     if (!mLineBuf.IsEmpty()) {
         NS_ASSERTION(mLineBuf.Length() < HTTPHeaderLen, "ouch");
         PRInt32 checkChars = PR_MIN(len, HTTPHeaderLen - mLineBuf.Length());
         if (PL_strncasecmp(buf, HTTPHeader + mLineBuf.Length(),
                            checkChars) == 0) {
             mLineBuf.Append(buf, checkChars);
@@ -709,23 +712,19 @@ nsHttpTransaction::LocateHttpStart(char 
         // pattern. Start the search again.
         mLineBuf.Truncate();
     }
 
     while (len > 0) {
         if (PL_strncasecmp(buf, HTTPHeader, PR_MIN(len, HTTPHeaderLen)) == 0) {
             if (len < HTTPHeaderLen) {
                 // partial HTTPHeader sequence found
-                if (aAllowPartialMatch) {
-                    return buf;
-                } else {
-                    // save partial match to mLineBuf
-                    mLineBuf.Assign(buf, len);
-                    return 0;
-                }
+                // save partial match to mLineBuf
+                mLineBuf.Assign(buf, len);
+                return 0;
             }
 
             // whole HTTPHeader sequence found
             return buf;
         }
         buf++;
         len--;
     }
@@ -823,17 +822,17 @@ nsHttpTransaction::ParseHead(char *buf,
         // Normally we insist on seeing HTTP/1.x in the first few bytes,
         // but if we are on a persistent connection and the previous transaction
         // was not supposed to have any content then we need to be prepared
         // to skip over a response body that the server may have sent even
         // though it wasn't allowed.
         if (!mConnection || !mConnection->LastTransactionExpectedNoContent()) {
             // tolerate only minor junk before the status line
             mHttpResponseMatched = PR_TRUE;
-            char *p = LocateHttpStart(buf, PR_MIN(count, 8), PR_TRUE);
+            char *p = LocateHttpStart(buf, PR_MIN(count, 11), PR_TRUE);
             if (!p) {
                 // Treat any 0.9 style response of a put as a failure.
                 if (mRequestHead->Method() == nsHttp::Put)
                     return NS_ERROR_ABORT;
 
                 mResponseHead->ParseStatusLine("");
                 mHaveStatusLine = PR_TRUE;
                 mHaveAllHeaders = PR_TRUE;