Changeset 155633 in webkit


Ignore:
Timestamp:
Sep 12, 2013 11:26:17 AM (11 years ago)
Author:
galpeter@inf.u-szeged.hu
Message:

[curl] Improve multipart response handling
https://bugs.webkit.org/show_bug.cgi?id=117735

Reviewed by Brent Fulgham.

The multipart/x-mixed-replace mime type in responses are ignored
with the curl network backend. To handle such responses the
MultipartHandle is introduced which will split the content using
the boundary specified by the mime type.

There are already existing tests (http/tests/multipart).

  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.vcxproj/WebCore.vcxproj.filters:
  • platform/network/HTTPParsers.cpp:

(WebCore::parseHTTPHeader):

  • platform/network/HTTPParsers.h:
  • platform/network/ResourceHandleInternal.h:
  • platform/network/curl/MultipartHandle.cpp: Added.

(WebCore::MultipartHandle::extractBoundary):
(WebCore::MultipartHandle::matchForBoundary):
(WebCore::MultipartHandle::checkForBoundary):
(WebCore::MultipartHandle::parseHeadersIfPossible):
(WebCore::MultipartHandle::contentReceived):
(WebCore::MultipartHandle::processContent):
(WebCore::MultipartHandle::contentEnded):
(WebCore::MultipartHandle::didReceiveData):
(WebCore::MultipartHandle::didReceiveResponse):

  • platform/network/curl/MultipartHandle.h: Added.

(WebCore::MultipartHandle::MultipartHandle):
(WebCore::MultipartHandle::~MultipartHandle):

  • platform/network/curl/ResourceHandleManager.cpp:

(WebCore::writeCallback):
(WebCore::headerCallback):
(WebCore::ResourceHandleManager::downloadTimerCallback):

Location:
trunk/Source/WebCore
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155631 r155633  
     12013-09-12  Peter Gal  <galpeter@inf.u-szeged.hu>
     2
     3        [curl] Improve multipart response handling
     4        https://bugs.webkit.org/show_bug.cgi?id=117735
     5
     6        Reviewed by Brent Fulgham.
     7
     8        The multipart/x-mixed-replace mime type in responses are ignored
     9        with the curl network backend. To handle such responses the
     10        MultipartHandle is introduced which will split the content using
     11        the boundary specified by the mime type.
     12
     13        There are already existing tests (http/tests/multipart).
     14
     15        * WebCore.vcxproj/WebCore.vcxproj:
     16        * WebCore.vcxproj/WebCore.vcxproj.filters:
     17        * platform/network/HTTPParsers.cpp:
     18        (WebCore::parseHTTPHeader):
     19        * platform/network/HTTPParsers.h:
     20        * platform/network/ResourceHandleInternal.h:
     21        * platform/network/curl/MultipartHandle.cpp: Added.
     22        (WebCore::MultipartHandle::extractBoundary):
     23        (WebCore::MultipartHandle::matchForBoundary):
     24        (WebCore::MultipartHandle::checkForBoundary):
     25        (WebCore::MultipartHandle::parseHeadersIfPossible):
     26        (WebCore::MultipartHandle::contentReceived):
     27        (WebCore::MultipartHandle::processContent):
     28        (WebCore::MultipartHandle::contentEnded):
     29        (WebCore::MultipartHandle::didReceiveData):
     30        (WebCore::MultipartHandle::didReceiveResponse):
     31        * platform/network/curl/MultipartHandle.h: Added.
     32        (WebCore::MultipartHandle::MultipartHandle):
     33        (WebCore::MultipartHandle::~MultipartHandle):
     34        * platform/network/curl/ResourceHandleManager.cpp:
     35        (WebCore::writeCallback):
     36        (WebCore::headerCallback):
     37        (WebCore::ResourceHandleManager::downloadTimerCallback):
     38
    1392013-09-12  Andreas Kling  <akling@apple.com>
    240
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r155631 r155633  
    83108310      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
    83118311      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     8312    </ClCompile>
     8313    <ClCompile Include="..\platform\network\curl\MultipartHandle.cpp">
     8314      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     8315      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
     8316      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     8317      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
    83128318    </ClCompile>
    83138319    <ClCompile Include="..\platform\network\curl\ProxyServerCurl.cpp">
     
    1967919685      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
    1968019686      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     19687    </CustomBuildStep>
     19688    <CustomBuildStep Include="..\platform\network\curl\MultipartHandle.h">
     19689      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     19690      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
     19691      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     19692      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
    1968119693    </CustomBuildStep>
    1968219694    <CustomBuildStep Include="..\platform\network\curl\ResourceError.h">
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

    r155631 r155633  
    19691969      <Filter>platform\network\curl</Filter>
    19701970    </ClCompile>
     1971    <ClCompile Include="..\platform\network\curl\MultipartHandle.cpp">
     1972      <Filter>platform\network\curl</Filter>
     1973    </ClCompile>
    19711974    <ClCompile Include="..\platform\network\curl\ProxyServerCurl.cpp">
    19721975      <Filter>platform\network\curl</Filter>
     
    1579615799      <Filter>platform\network\curl</Filter>
    1579715800    </CustomBuildStep>
     15801    <CustomBuildStep Include="..\platform\network\curl\MultipartHandle.h">
     15802      <Filter>platform\network\curl</Filter>
     15803    </CustomBuildStep>
    1579815804    <CustomBuildStep Include="..\platform\network\curl\ResourceError.h">
    1579915805      <Filter>platform\network\curl</Filter>
  • trunk/Source/WebCore/platform/network/HTTPParsers.cpp

    r147086 r155633  
    606606}
    607607
    608 size_t parseHTTPHeader(const char* start, size_t length, String& failureReason, AtomicString& nameStr, String& valueStr)
     608size_t parseHTTPHeader(const char* start, size_t length, String& failureReason, AtomicString& nameStr, String& valueStr, bool strict)
    609609{
    610610    const char* p = start;
     
    649649            break;
    650650        case '\n':
    651             failureReason = "Unexpected LF in value at " + trimInputSample(value.data(), value.size());
    652             return 0;
     651            if (strict) {
     652                failureReason = "Unexpected LF in value at " + trimInputSample(value.data(), value.size());
     653                return 0;
     654            }
     655            break;
    653656        default:
    654657            value.append(*p);
    655658        }
    656         if (*p == '\r') {
     659        if (*p == '\r' || (!strict && *p == '\n')) {
    657660            ++p;
    658661            break;
    659662        }
    660663    }
    661     if (p >= end || *p != '\n') {
     664    if (p >= end || (strict && *p != '\n')) {
    662665        failureReason = "CR doesn't follow LF after value at " + trimInputSample(p, end - p);
    663666        return 0;
  • trunk/Source/WebCore/platform/network/HTTPParsers.h

    r153039 r155633  
    8787enum HTTPVersion { Unknown, HTTP_1_0, HTTP_1_1 };
    8888size_t parseHTTPRequestLine(const char* data, size_t length, String& failureReason, String& method, String& url, HTTPVersion&);
    89 size_t parseHTTPHeader(const char* data, size_t length, String& failureReason, AtomicString& nameStr, String& valueStr);
     89size_t parseHTTPHeader(const char* data, size_t length, String& failureReason, AtomicString& nameStr, String& valueStr, bool strict = true);
    9090size_t parseHTTPRequestBody(const char* data, size_t length, Vector<unsigned char>& body);
    9191
  • trunk/Source/WebCore/platform/network/ResourceHandleInternal.h

    r152908 r155633  
    4545#include <curl/curl.h>
    4646#include "FormDataStreamCurl.h"
     47#include "MultipartHandle.h"
    4748#endif
    4849
     
    191192        FormDataStream m_formDataStream;
    192193        Vector<char> m_postBytes;
     194
     195        OwnPtr<MultipartHandle> m_multipartHandle;
    193196#endif
    194197#if USE(SOUP)
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp

    r154386 r155633  
    4040#include "HTTPParsers.h"
    4141#include "MIMETypeRegistry.h"
     42#include "MultipartHandle.h"
    4243#include "NotImplemented.h"
    4344#include "ResourceError.h"
     
    241242    }
    242243
    243     if (d->client())
     244    if (d->m_multipartHandle)
     245        d->m_multipartHandle->contentReceived(static_cast<const char*>(ptr), totalSize);
     246    else if (d->client())
    244247        d->client()->didReceiveData(job, static_cast<char*>(ptr), totalSize, 0);
     248
    245249    return totalSize;
    246250}
     
    397401        d->m_response.setSuggestedFilename(filenameFromHTTPContentDisposition(d->m_response.httpHeaderField("Content-Disposition")));
    398402
     403        if (d->m_response.isMultipart()) {
     404            String boundary;
     405            bool parsed = MultipartHandle::extractBoundary(d->m_response.httpHeaderField("Content-Type"), boundary);
     406            if (parsed)
     407                d->m_multipartHandle = MultipartHandle::create(job, boundary);
     408        }
     409
    399410        // HTTP redirection
    400411        if (isHttpRedirect(httpCode)) {
     
    566577                }
    567578            }
     579
     580            if (d->m_multipartHandle)
     581                d->m_multipartHandle->contentEnded();
    568582
    569583            if (d->client())
Note: See TracChangeset for help on using the changeset viewer.