[BlackBerry] NetworkJob should not check if data is received with HEAD
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:28:49 +0000 (06:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:28:49 +0000 (06:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102034

Patch by Joe Mason <jmason@rim.com> on 2012-11-12
Reviewed by George Staikos.

Internal PR: 241391

.:

Add test that HEAD XMLHttpRequests return status 404 instead of calling onerror.

* ManualTests/blackberry/head-xhr-nonexistant-file.html: Added.

Source/WebCore:

Make HEAD requests call didFinish instead of didFail on a 404 response, even though they
have no data.

Tests: ManualTests/blackberry/head-xhr-nonexistant-file.html

* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::NetworkJob):
(WebCore::NetworkJob::initialize):
(WebCore::NetworkJob::shouldNotifyClientFailed):
* platform/network/blackberry/NetworkJob.h:
(NetworkJob):

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

ChangeLog
ManualTests/blackberry/head-xhr-nonexistant-file.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/network/blackberry/NetworkJob.cpp
Source/WebCore/platform/network/blackberry/NetworkJob.h

index bd7a68c..b63f501 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-11-12  Joe Mason  <jmason@rim.com>
+
+        [BlackBerry] NetworkJob should not check if data is received with HEAD
+        https://bugs.webkit.org/show_bug.cgi?id=102034
+
+        Reviewed by George Staikos.
+
+        Internal PR: 241391
+
+        Add test that HEAD XMLHttpRequests return status 404 instead of calling onerror.
+
+        * ManualTests/blackberry/head-xhr-nonexistant-file.html: Added.
+
 2012-11-12  KyungTae Kim  <ktf.kim@samsung.com>
 
         [EFL] Turn on error on warnings for "switch"
diff --git a/ManualTests/blackberry/head-xhr-nonexistant-file.html b/ManualTests/blackberry/head-xhr-nonexistant-file.html
new file mode 100644 (file)
index 0000000..882b6cc
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+<head>
+<script>
+var xhr = new XMLHttpRequest();
+xhr.open("HEAD", "nothing.txt", true);
+xhr.onreadystatechange = function() {
+    if (xhr.readyState != 4) {
+        return;
+    }
+    if (xhr.status == 404) {
+        alert("PASSED: onreadystatechange fired with status 404");
+    } else {
+        alert("FAILED: onreadystatechange fired with status " + xhr.status);
+    }
+
+}
+xhr.onerror = function() {
+    alert("FAILED: onerror fired");
+}
+xhr.send();
+</script>
+</head>
+<body>
+<p>This test must be hosted on a web server, not run from a file url, because XMLHttpRequest from file url causes a security error.</p>
+<p>You should see an alert box saying whether the test was passed or failed. If there is no alert box, the test was FAILED.</p>
+</body>
+</html>
index 073a305..2133696 100644 (file)
@@ -1,3 +1,24 @@
+2012-11-12  Joe Mason  <jmason@rim.com>
+
+        [BlackBerry] NetworkJob should not check if data is received with HEAD
+        https://bugs.webkit.org/show_bug.cgi?id=102034
+
+        Reviewed by George Staikos.
+
+        Internal PR: 241391
+
+        Make HEAD requests call didFinish instead of didFail on a 404 response, even though they
+        have no data.
+
+        Tests: ManualTests/blackberry/head-xhr-nonexistant-file.html
+
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::NetworkJob):
+        (WebCore::NetworkJob::initialize):
+        (WebCore::NetworkJob::shouldNotifyClientFailed):
+        * platform/network/blackberry/NetworkJob.h:
+        (NetworkJob):
+
 2012-11-12  Adam Barth  <abarth@webkit.org>
 
         [V8] V8DOMWrapper::instantiateV8Object shouldn't use deprecatedDocument
index 9977ef9..834bb2a 100644 (file)
@@ -81,6 +81,7 @@ NetworkJob::NetworkJob()
     , m_needsRetryAsFTPDirectory(false)
     , m_isOverrideContentType(false)
     , m_newJobWithCredentialsStarted(false)
+    , m_isHeadMethod(false)
     , m_extendedStatusCode(0)
     , m_redirectCount(0)
     , m_deferredData(*this)
@@ -106,6 +107,8 @@ bool NetworkJob::initialize(int playerId,
                             int deferLoadingCount,
                             int redirectCount)
 {
+    BLACKBERRY_ASSERT(handle);
+
     m_playerId = playerId;
     m_pageGroupName = pageGroupName;
 
@@ -128,6 +131,8 @@ bool NetworkJob::initialize(int playerId,
     m_redirectCount = redirectCount;
     m_deferLoadingCount = deferLoadingCount;
 
+    m_isHeadMethod = m_handle->firstRequest().httpMethod().upper() == "HEAD";
+
     // We don't need to explicitly call notifyHeaderReceived, as the Content-Type
     // will ultimately get parsed when sendResponseIfNeeded gets called.
     if (!request.getOverrideContentType().empty()) {
@@ -539,7 +544,7 @@ bool NetworkJob::shouldReleaseClientResource()
 
 bool NetworkJob::shouldNotifyClientFailed() const
 {
-    return m_extendedStatusCode < 0 || (isError(m_extendedStatusCode) && !m_dataReceived);
+    return m_extendedStatusCode < 0 || (isError(m_extendedStatusCode) && !m_dataReceived && !m_isHeadMethod);
 }
 
 bool NetworkJob::retryAsFTPDirectory()
index 4e5749e..18a29c2 100644 (file)
@@ -164,6 +164,7 @@ private:
     bool m_needsRetryAsFTPDirectory;
     bool m_isOverrideContentType;
     bool m_newJobWithCredentialsStarted;
+    bool m_isHeadMethod;
 
     // If an HTTP status code is received, m_extendedStatusCode and m_response.httpStatusCode will both be set to it.
     // If a platform error code is received, m_extendedStatusCode will be set to it and m_response.httpStatusCode will be set to 404.