Mirror Mozilla behavior for when to follow Content-Length
authorBenjamin Otte <otte@gnome.org>
Tue, 4 Aug 2009 10:11:03 +0000 (12:11 +0200)
committerBenjamin Otte <otte@gnome.org>
Tue, 4 Aug 2009 19:25:31 +0000 (21:25 +0200)
Mozilla only honors content length on messages that use keep-alive to
work around servers that send broken Content-Length headers. This patch
mirrors that behavior.

An example for such a page is
http://sourceforge.net/apps/wordpress/sourceforge

libsoup/soup-message-client-io.c

index 8159922..654b320 100644 (file)
@@ -56,6 +56,18 @@ parse_response_headers (SoupMessage *req,
        if (*encoding == SOUP_ENCODING_UNRECOGNIZED)
                return SOUP_STATUS_MALFORMED;
 
+        /* mirror Mozilla here:
+         * (see netwerk/protocol/http/src/nsHttpTransaction.cpp for details)
+         *
+         * HTTP servers have been known to send erroneous Content-Length headers.
+         * So, unless the connection is persistent, we must make allowances for a
+         * possibly invalid Content-Length header. Thus, if NOT persistent, we 
+         * simply accept the whole message.
+         */
+        if (*encoding == SOUP_ENCODING_CONTENT_LENGTH &&
+            !soup_message_is_keepalive (req))
+                *encoding = SOUP_ENCODING_EOF;
+
        return SOUP_STATUS_OK;
 }