Title: [149672] trunk/Source/WebCore
Revision
149672
Author
commit-qu...@webkit.org
Date
2013-05-07 08:53:34 -0700 (Tue, 07 May 2013)

Log Message

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

Patch by pe...@outlook.com <pe...@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'.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149671 => 149672)


--- trunk/Source/WebCore/ChangeLog	2013-05-07 15:33:02 UTC (rev 149671)
+++ trunk/Source/WebCore/ChangeLog	2013-05-07 15:53:34 UTC (rev 149672)
@@ -1,3 +1,25 @@
+2013-05-07  pe...@outlook.com  <pe...@outlook.com>
+
+        [Curl] POST requests sometimes fail.
+        https://bugs.webkit.org/show_bug.cgi?id=111844
+
+        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'.
+
 2013-05-07  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [X11][BlackBerry] Check if MOZ_X11 is defined instead of XP_UNIX npruntime_internal.h

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp (149671 => 149672)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp	2013-05-07 15:33:02 UTC (rev 149671)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp	2013-05-07 15:53:34 UTC (rev 149672)
@@ -126,6 +126,16 @@
         mutex->unlock();
 }
 
+inline static bool isHttpInfo(int statusCode)
+{
+    return 100 <= statusCode && statusCode < 200;
+}
+
+inline static bool isHttpRedirect(int statusCode)
+{
+    return 300 <= statusCode && statusCode < 400 && statusCode != 304;
+}
+
 ResourceHandleManager::ResourceHandleManager()
     : m_downloadTimer(this, &ResourceHandleManager::downloadTimerCallback)
     , m_cookieJarFileName(cookieJarPath())
@@ -264,6 +274,15 @@
         CURL* h = d->m_handle;
         CURLcode err;
 
+        long httpCode = 0;
+        err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode);
+
+        if (isHttpInfo(httpCode)) {
+            // Just return when receiving http info, e.g. HTTP/1.1 100 Continue.
+            // If not, the request might be cancelled, because the MIME type will be empty for this response.
+            return totalSize;
+        }
+
         double contentLength = 0;
         err = curl_easy_getinfo(h, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
         d->m_response.setExpectedContentLength(static_cast<long long int>(contentLength));
@@ -272,16 +291,13 @@
         err = curl_easy_getinfo(h, CURLINFO_EFFECTIVE_URL, &hdr);
         d->m_response.setURL(KURL(ParsedURLString, hdr));
 
-        long httpCode = 0;
-        err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode);
         d->m_response.setHTTPStatusCode(httpCode);
-
         d->m_response.setMimeType(extractMIMETypeFromMediaType(d->m_response.httpHeaderField("Content-Type")));
         d->m_response.setTextEncodingName(extractCharsetFromMediaType(d->m_response.httpHeaderField("Content-Type")));
         d->m_response.setSuggestedFilename(filenameFromHTTPContentDisposition(d->m_response.httpHeaderField("Content-Disposition")));
 
         // HTTP redirection
-        if (httpCode >= 300 && httpCode < 400) {
+        if (isHttpRedirect(httpCode)) {
             String location = d->m_response.httpHeaderField("location");
             if (!location.isEmpty()) {
                 KURL newURL = KURL(job->firstRequest().url(), location);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to