=== modified file 'src/http.cc' --- src/http.cc 2009-07-26 10:54:29 +0000 +++ src/http.cc 2009-07-31 06:44:31 +0000 @@ -710,42 +710,50 @@ HttpReply *newrep = new HttpReply; const bool parsed = newrep->parse(readBuf, eof, &error); - if(!parsed && readBuf->contentSize() > 5 && strncmp(readBuf->content(), "HTTP/", 5) != 0){ - MemBuf *mb; - HttpReply *tmprep = new HttpReply; - tmprep->sline.version = HttpVersion(1, 0); - tmprep->sline.status = HTTP_OK; - tmprep->header.putTime(HDR_DATE, squid_curtime); - tmprep->header.putExt("X-Transformed-From", "HTTP/0.9"); - mb = tmprep->pack(); - newrep->parse(mb, eof, &error); - delete tmprep; - } - else{ - if (!parsed && error > 0) { // unrecoverable parsing error - debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf->content() << "'"); - flags.headers_parsed = 1; - newrep->sline.version = HttpVersion(1, 0); - newrep->sline.status = error; - HttpReply *vrep = setVirginReply(newrep); - entry->replaceHttpReply(vrep); - ctx_exit(ctx); - return; - } - - if (!parsed) { // need more data - assert(!error); - assert(!eof); - delete newrep; - ctx_exit(ctx); - return; - } - - debugs(11, 9, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------"); - - header_bytes_read = headersEnd(readBuf->content(), readBuf->contentSize()); - readBuf->consume(header_bytes_read); - } + if(!parsed) { + + if(readBuf->contentSize() > 5 && strncmp(readBuf->content(), "HTTP/", 5) != 0) { // HTTP legacy 0.9 + MemBuf *mb; + HttpReply *tmprep = new HttpReply; + tmprep->sline.version = HttpVersion(1, 0); + tmprep->sline.status = HTTP_OK; + tmprep->header.putTime(HDR_DATE, squid_curtime); + tmprep->header.putExt("X-Transformed-From", "HTTP/0.9"); + mb = tmprep->pack(); + newrep->parse(mb, eof, &error); + delete tmprep; + } + else if (error > 0) { // unrecoverable parsing error + debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf->content() << "'"); + flags.headers_parsed = 1; + newrep->sline.version = HttpVersion(1, 0); + newrep->sline.status = error; + HttpReply *vrep = setVirginReply(newrep); + entry->replaceHttpReply(vrep); + ctx_exit(ctx); + return; + } + else if (eof) { // EOF but non-parsed ?! + /* AYJ: 2009-07-26: this _should_ only occur on aborted connections. + * Unfortunately: + * - may occur on persistent connections closed by a broken server mid-headers. + * - some platforms when read returns zero bytes despite connection remaining live. + */ + debugs(11, 2, "EOF in non-complete HTTP reply header (" << readBuf.size() << " bytes):\n---------\n" << readBuf->content() << "\n----------"); + delete newrep; + ctx_exit(ctx); + return; + } + else { // !error && !eof -> need more data + delete newrep; + ctx_exit(ctx); + return; + } + } + + debugs(11, 9, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------"); + header_bytes_read = headersEnd(readBuf->content(), readBuf->contentSize()); + readBuf->consume(header_bytes_read); flags.chunked = 0; if (newrep->header.hasListMember(HDR_TRANSFER_ENCODING, "chunked", ',')) { @@ -1002,7 +1010,7 @@ } // update I/O stats - if (len > 0) { + if (len => 0) { readBuf->appended(len); reply_bytes_read += len; #if DELAY_POOLS @@ -1045,6 +1053,7 @@ #endif if (len == 0) { // reached EOF? + debugs(11, 2, "Reached EOF for HTTP reply on FD " << fd << ". flag=" << flag); eof = 1; flags.do_next_read = 0; }