Changeset 149672 in webkit


Ignore:
Timestamp:
May 7, 2013 8:53:34 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Curl] POST requests sometimes fail.
https://bugs.webkit.org/show_bug.cgi?id=111844

Patch by peavo@outlook.com <peavo@outlook.com> on 2013-05-07
Reviewed by Brent Fulgham.

Curl adds the header 'Expect: 100-Continue' when sending a POST request.
When we receive the header 'HTTP/1.1 100 Continue', we should not call
ResourceHandleClient::didReceiveResponse(), as this will cancel the request,
because the MIME type is empty in this case, causing the POST request to fail.
This header is only sent as an info header, or provisional response.

In addition, this patch changes the classification of http code 304 (Not modified).
It is not reported as a redirect anymore, but as a response
(ResourceHandleClient::didReceiveResponse() is called.

  • platform/network/curl/ResourceHandleManager.cpp:

(WebCore::isHttpInfo): Added helper method to determine if http code is http info.
(WebCore::isHttpRedirect): Added helper method to determine if http code is http redirect.
(WebCore::headerCallback): Just return when receiving the header'HTTP/1.1 100 Continue'.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r149669 r149672  
     12013-05-07  peavo@outlook.com  <peavo@outlook.com>
     2
     3        [Curl] POST requests sometimes fail.
     4        https://bugs.webkit.org/show_bug.cgi?id=111844
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Curl adds the header 'Expect: 100-Continue' when sending a POST request.
     9        When we receive the header 'HTTP/1.1 100 Continue', we should not call
     10        ResourceHandleClient::didReceiveResponse(), as this will cancel the request,
     11        because the MIME type is empty in this case, causing the POST request to fail.
     12        This header is only sent as an info header, or provisional response.
     13       
     14        In addition, this patch changes the classification of http code 304 (Not modified).
     15        It is not reported as a redirect anymore, but as a response
     16        (ResourceHandleClient::didReceiveResponse() is called.
     17
     18        * platform/network/curl/ResourceHandleManager.cpp:
     19        (WebCore::isHttpInfo): Added helper method to determine if http code is http info.
     20        (WebCore::isHttpRedirect): Added helper method to determine if http code is http redirect.
     21        (WebCore::headerCallback): Just return when receiving the header'HTTP/1.1 100 Continue'.
     22
    1232013-05-07  Carlos Garcia Campos  <cgarcia@igalia.com>
    224
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp

    r146621 r149672  
    127127}
    128128
     129inline static bool isHttpInfo(int statusCode)
     130{
     131    return 100 <= statusCode && statusCode < 200;
     132}
     133
     134inline static bool isHttpRedirect(int statusCode)
     135{
     136    return 300 <= statusCode && statusCode < 400 && statusCode != 304;
     137}
     138
    129139ResourceHandleManager::ResourceHandleManager()
    130140    : m_downloadTimer(this, &ResourceHandleManager::downloadTimerCallback)
     
    265275        CURLcode err;
    266276
     277        long httpCode = 0;
     278        err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode);
     279
     280        if (isHttpInfo(httpCode)) {
     281            // Just return when receiving http info, e.g. HTTP/1.1 100 Continue.
     282            // If not, the request might be cancelled, because the MIME type will be empty for this response.
     283            return totalSize;
     284        }
     285
    267286        double contentLength = 0;
    268287        err = curl_easy_getinfo(h, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
     
    273292        d->m_response.setURL(KURL(ParsedURLString, hdr));
    274293
    275         long httpCode = 0;
    276         err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode);
    277294        d->m_response.setHTTPStatusCode(httpCode);
    278 
    279295        d->m_response.setMimeType(extractMIMETypeFromMediaType(d->m_response.httpHeaderField("Content-Type")));
    280296        d->m_response.setTextEncodingName(extractCharsetFromMediaType(d->m_response.httpHeaderField("Content-Type")));
     
    282298
    283299        // HTTP redirection
    284         if (httpCode >= 300 && httpCode < 400) {
     300        if (isHttpRedirect(httpCode)) {
    285301            String location = d->m_response.httpHeaderField("location");
    286302            if (!location.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.