Disable HTTP request "Accept-Encoding:" header field on gstreamer source element...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Aug 2013 18:40:31 +0000 (18:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Aug 2013 18:40:31 +0000 (18:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=115354

Patch by Andre Moreira Magalhaes <andre.magalhaes@collabora.co.uk> on 2013-08-07
Reviewed by Philippe Normand.

The default value for the HTTP "Accept-Encoding:" header field in the request allows
compressed data to be received on requests.
While this works fine for most cases, it can break the webkit source that needs to rely on the
the proper data size when receiving the response (even though the received data is already
uncompressed the size reported in ResourceResponse::expectedContentLength() is the same
represented by the HTTP header field "Content-Length" which is the size of the compressed data).

This patch disables the HTTP "Accept-Encoding:" header field when using the request
as we don't want the received response to be encoded in any way, as we need to rely on the proper
size of the returned data on ResourceHandle::didReceiveResponse().

* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(webKitWebSrcStart):
* platform/network/soup/ResourceRequest.h:
(ResourceRequestBase):
(WebCore::ResourceRequest::acceptEncoding):
(WebCore::ResourceRequest::setAcceptEncoding):
(WebCore::ResourceRequest::ResourceRequestBase):
* platform/network/soup/ResourceRequestSoup.cpp:
(WebCore::ResourceRequest::updateSoupMessage):
(WebCore::ResourceRequest::toSoupMessage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@153795 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp
Source/WebCore/platform/network/soup/ResourceRequest.h
Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp

index 6abe5dc..a9333b0 100644 (file)
@@ -1,3 +1,32 @@
+2013-08-07  Andre Moreira Magalhaes   <andre.magalhaes@collabora.co.uk>
+
+        Disable HTTP request "Accept-Encoding:" header field on gstreamer source element to avoid receiving the wrong size when retrieving data
+        https://bugs.webkit.org/show_bug.cgi?id=115354
+
+        Reviewed by Philippe Normand.
+
+        The default value for the HTTP "Accept-Encoding:" header field in the request allows
+        compressed data to be received on requests.
+        While this works fine for most cases, it can break the webkit source that needs to rely on the
+        the proper data size when receiving the response (even though the received data is already
+        uncompressed the size reported in ResourceResponse::expectedContentLength() is the same
+        represented by the HTTP header field "Content-Length" which is the size of the compressed data).
+
+        This patch disables the HTTP "Accept-Encoding:" header field when using the request
+        as we don't want the received response to be encoded in any way, as we need to rely on the proper
+        size of the returned data on ResourceHandle::didReceiveResponse().
+
+        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+        (webKitWebSrcStart):
+        * platform/network/soup/ResourceRequest.h:
+        (ResourceRequestBase):
+        (WebCore::ResourceRequest::acceptEncoding):
+        (WebCore::ResourceRequest::setAcceptEncoding):
+        (WebCore::ResourceRequest::ResourceRequestBase):
+        * platform/network/soup/ResourceRequestSoup.cpp:
+        (WebCore::ResourceRequest::updateSoupMessage):
+        (WebCore::ResourceRequest::toSoupMessage):
+
 2013-08-07  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         [Qt] REGRESSION(r) Two pixel result fail after r153522
index c61e314..0cc575e 100644 (file)
@@ -440,6 +440,16 @@ static bool webKitWebSrcStart(WebKitWebSrc* src)
     request.setAllowCookies(true);
     request.setHTTPReferrer(priv->player->referrer());
 
+#if USE(SOUP)
+    // Let's disable HTTP Accept-Encoding here as we don't want the received response to be
+    // encoded in any way as we need to rely on the proper size of the returned data on
+    // didReceiveResponse.
+    // If Accept-Encoding is used, the server may send the data in encoded format and
+    // request.expectedContentLength() will have the "wrong" size (the size of the
+    // compressed data), even though the data received in didReceiveData is uncompressed.
+    request.setAcceptEncoding(false);
+#endif
+
     // Let Apple web servers know we want to access their nice movie trailers.
     if (!g_ascii_strcasecmp("movies.apple.com", url.host().utf8().data())
         || !g_ascii_strcasecmp("trailers.apple.com", url.host().utf8().data()))
index 873c3d2..730a287 100644 (file)
@@ -36,18 +36,21 @@ namespace WebCore {
     public:
         ResourceRequest(const String& url)
             : ResourceRequestBase(KURL(ParsedURLString, url), UseProtocolCachePolicy)
+            , m_acceptEncoding(true)
             , m_soupFlags(static_cast<SoupMessageFlags>(0))
         {
         }
 
         ResourceRequest(const KURL& url)
             : ResourceRequestBase(url, UseProtocolCachePolicy)
+            , m_acceptEncoding(true)
             , m_soupFlags(static_cast<SoupMessageFlags>(0))
         {
         }
 
         ResourceRequest(const KURL& url, const String& referrer, ResourceRequestCachePolicy policy = UseProtocolCachePolicy)
             : ResourceRequestBase(url, policy)
+            , m_acceptEncoding(true)
             , m_soupFlags(static_cast<SoupMessageFlags>(0))
         {
             setHTTPReferrer(referrer);
@@ -55,12 +58,14 @@ namespace WebCore {
 
         ResourceRequest()
             : ResourceRequestBase(KURL(), UseProtocolCachePolicy)
+            , m_acceptEncoding(true)
             , m_soupFlags(static_cast<SoupMessageFlags>(0))
         {
         }
 
         ResourceRequest(SoupMessage* soupMessage)
             : ResourceRequestBase(KURL(), UseProtocolCachePolicy)
+            , m_acceptEncoding(true)
             , m_soupFlags(static_cast<SoupMessageFlags>(0))
         {
             updateFromSoupMessage(soupMessage);
@@ -68,6 +73,9 @@ namespace WebCore {
 
         void updateFromDelegatePreservingOldHTTPBody(const ResourceRequest& delegateProvidedRequest) { *this = delegateProvidedRequest; }
 
+        bool acceptEncoding() const { return m_acceptEncoding; }
+        void setAcceptEncoding(bool acceptEncoding) { m_acceptEncoding = acceptEncoding; }
+
         void updateSoupMessageHeaders(SoupMessageHeaders*) const;
         void updateFromSoupMessageHeaders(SoupMessageHeaders*);
         void updateSoupMessage(SoupMessage*) const;
@@ -82,6 +90,7 @@ namespace WebCore {
     private:
         friend class ResourceRequestBase;
 
+        bool m_acceptEncoding : 1;
         SoupMessageFlags m_soupFlags;
 
         void doUpdatePlatformRequest() { }
index 752388b..c95cdc5 100644 (file)
@@ -69,6 +69,9 @@ void ResourceRequest::updateSoupMessage(SoupMessage* soupMessage) const
     }
 
     soup_message_set_flags(soupMessage, m_soupFlags);
+
+    if (!acceptEncoding())
+        soup_message_disable_feature(soupMessage, SOUP_TYPE_CONTENT_DECODER);
 }
 
 SoupMessage* ResourceRequest::toSoupMessage() const