Diff
Modified: trunk/Source/WebCore/ChangeLog (222011 => 222012)
--- trunk/Source/WebCore/ChangeLog 2017-09-14 06:19:08 UTC (rev 222011)
+++ trunk/Source/WebCore/ChangeLog 2017-09-14 06:57:12 UTC (rev 222012)
@@ -1,3 +1,31 @@
+2017-09-13 Basuke Suzuki <[email protected]>
+
+ [Curl] Move response related features into ResourceResponse
+ https://bugs.webkit.org/show_bug.cgi?id=174654
+
+ Reviewed by Alex Christensen.
+
+ * platform/Curl.cmake:
+ * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+ (WebCore::ResourceHandleCurlDelegate::didReceiveAllHeaders):
+ (WebCore::ResourceHandleCurlDelegate::didReceiveHeader):
+ (WebCore::isHttpRedirect): Deleted.
+ (WebCore::isHttpAuthentication): Deleted.
+ (WebCore::isHttpNotModified): Deleted.
+ (WebCore::isAppendableHeader): Deleted.
+ (WebCore::ResourceHandleCurlDelegate::didReceiveHeaderLine): Deleted.
+ * platform/network/curl/ResourceHandleCurlDelegate.h:
+ * platform/network/curl/ResourceResponse.h:
+ (WebCore::ResourceResponse::platformSuggestedFilename const): Deleted.
+ * platform/network/curl/ResourceResponseCurl.cpp: Added.
+ (WebCore::ResourceResponse::isAppendableHeader):
+ (WebCore::ResourceResponse::appendHTTPHeaderField):
+ (WebCore::ResourceResponse::setStatusLine):
+ (WebCore::ResourceResponse::platformSuggestedFilename const):
+ (WebCore::ResourceResponse::isRedirection const):
+ (WebCore::ResourceResponse::isNotModified const):
+ (WebCore::ResourceResponse::isUnauthorized const):
+
2017-09-13 Zalan Bujtas <[email protected]>
Switch multicolumn's spanner map from raw over to weak pointers.
Modified: trunk/Source/WebCore/platform/Curl.cmake (222011 => 222012)
--- trunk/Source/WebCore/platform/Curl.cmake 2017-09-14 06:19:08 UTC (rev 222011)
+++ trunk/Source/WebCore/platform/Curl.cmake 2017-09-14 06:57:12 UTC (rev 222012)
@@ -16,6 +16,7 @@
platform/network/curl/ProxyServerCurl.cpp
platform/network/curl/ResourceHandleCurl.cpp
platform/network/curl/ResourceHandleCurlDelegate.cpp
+ platform/network/curl/ResourceResponseCurl.cpp
platform/network/curl/SSLHandle.cpp
platform/network/curl/SocketStreamHandleImplCurl.cpp
platform/network/curl/SynchronousLoaderClientCurl.cpp
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (222011 => 222012)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-14 06:19:08 UTC (rev 222011)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-14 06:57:12 UTC (rev 222012)
@@ -34,6 +34,7 @@
#include "CredentialStorage.h"
#include "CurlCacheManager.h"
+#include "HTTPParsers.h"
#include "MIMETypeRegistry.h"
#include "MultipartHandle.h"
#include "ResourceHandle.h"
@@ -402,98 +403,6 @@
return 100 <= statusCode && statusCode < 200;
}
-inline static bool isHttpRedirect(int statusCode)
-{
- return 300 <= statusCode && statusCode < 400 && statusCode != 304;
-}
-
-inline static bool isHttpAuthentication(int statusCode)
-{
- return statusCode == 401;
-}
-
-inline static bool isHttpNotModified(int statusCode)
-{
- return statusCode == 304;
-}
-
-static bool isAppendableHeader(const String &key)
-{
- static const char* appendableHeaders[] = {
- "access-control-allow-headers",
- "access-control-allow-methods",
- "access-control-allow-origin",
- "access-control-expose-headers",
- "allow",
- "cache-control",
- "connection",
- "content-encoding",
- "content-language",
- "if-match",
- "if-none-match",
- "keep-alive",
- "pragma",
- "proxy-authenticate",
- "public",
- "server",
- "set-cookie",
- "te",
- "trailer",
- "transfer-encoding",
- "upgrade",
- "user-agent",
- "vary",
- "via",
- "warning",
- "www-authenticate"
- };
-
- // Custom headers start with 'X-', and need no further checking.
- if (key.startsWith("x-", /* caseSensitive */ false))
- return true;
-
- for (auto& header : appendableHeaders) {
- if (equalIgnoringASCIICase(key, header))
- return true;
- }
-
- return false;
-}
-
-void ResourceHandleCurlDelegate::didReceiveHeaderLine(const String& header)
-{
- ASSERT(isMainThread());
-
- auto splitPosition = header.find(":");
- if (splitPosition != notFound) {
- String key = header.left(splitPosition).stripWhiteSpace();
- String value = header.substring(splitPosition + 1).stripWhiteSpace();
-
- if (isAppendableHeader(key))
- response().addHTTPHeaderField(key, value);
- else
- response().setHTTPHeaderField(key, value);
- } else if (header.startsWith("HTTP", false)) {
- // This is the first line of the response.
- // Extract the http status text from this.
- //
- // If the FOLLOWLOCATION option is enabled for the curl handle then
- // curl will follow the redirections internally. Thus this header callback
- // will be called more than one time with the line starting "HTTP" for one job.
- long httpCode = 0;
- m_curlHandle.getResponseCode(httpCode);
-
- String httpCodeString = String::number(httpCode);
- int statusCodePos = header.find(httpCodeString);
-
- if (statusCodePos != notFound) {
- // The status text is after the status code.
- String status = header.substring(statusCodePos + httpCodeString.length());
- response().setHTTPStatusText(status.stripWhiteSpace());
- }
- }
-}
-
void ResourceHandleCurlDelegate::didReceiveAllHeaders(long httpCode, long long contentLength)
{
ASSERT(isMainThread());
@@ -512,7 +421,7 @@
}
// HTTP redirection
- if (isHttpRedirect(httpCode)) {
+ if (response().isRedirection()) {
String location = response().httpHeaderField(HTTPHeaderName::Location);
if (!location.isEmpty()) {
URL newURL = URL(m_firstRequest.url(), location);
@@ -527,7 +436,7 @@
return;
}
- } else if (isHttpAuthentication(httpCode)) {
+ } else if (response().isUnauthorized()) {
ProtectionSpace protectionSpace;
if (getProtectionSpace(response(), protectionSpace)) {
Credential credential;
@@ -542,7 +451,7 @@
response().setResponseFired(true);
if (m_handle->client()) {
- if (isHttpNotModified(httpCode)) {
+ if (response().isNotModified()) {
const String& url = ""
if (CurlCacheManager::getInstance().getCachedResponse(url, response())) {
if (m_addedCacheValidationHeaders) {
@@ -878,13 +787,17 @@
});
}
} else {
+ // If the FOLLOWLOCATION option is enabled for the curl handle then
+ // curl will follow the redirections internally. Thus this header callback
+ // will be called more than one time with the line starting "HTTP" for one job.
if (isMainThread())
- didReceiveHeaderLine(header);
+ response().appendHTTPHeaderField(header);
else {
- callOnMainThread([protectedThis = makeRef(*this), header = header.isolatedCopy() ] {
+ callOnMainThread([protectedThis = makeRef(*this), copyHeader = header.isolatedCopy() ] {
if (!protectedThis->m_handle)
return;
- protectedThis->didReceiveHeaderLine(header);
+
+ protectedThis->response().appendHTTPHeaderField(copyHeader);
});
}
}
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h (222011 => 222012)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-14 06:19:08 UTC (rev 222011)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-14 06:57:12 UTC (rev 222012)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 NAVER Corp. All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -74,7 +75,6 @@
void setupAuthentication();
bool getProtectionSpace(const ResourceResponse&, ProtectionSpace&);
- void didReceiveHeaderLine(const String&);
void didReceiveAllHeaders(long httpCode, long long contentLength);
void didReceiveContentData(ThreadSafeDataBuffer);
void handleLocalReceiveResponse();
Modified: trunk/Source/WebCore/platform/network/curl/ResourceResponse.h (222011 => 222012)
--- trunk/Source/WebCore/platform/network/curl/ResourceResponse.h 2017-09-14 06:19:08 UTC (rev 222011)
+++ trunk/Source/WebCore/platform/network/curl/ResourceResponse.h 2017-09-14 06:57:12 UTC (rev 222012)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,9 +26,6 @@
#pragma once
-#include "HTTPHeaderNames.h"
-#include "HTTPParsers.h"
-
#include "ResourceResponseBase.h"
typedef struct _CFURLResponse* CFURLResponseRef;
@@ -50,6 +48,12 @@
void setResponseFired(bool fired) { m_responseFired = fired; }
bool responseFired() { return m_responseFired; }
+ void appendHTTPHeaderField(const String&);
+
+ bool isRedirection() const;
+ bool isNotModified() const;
+ bool isUnauthorized() const;
+
// Needed for compatibility.
CFURLResponseRef cfURLResponse() const { return 0; }
@@ -56,11 +60,11 @@
private:
friend class ResourceResponseBase;
- String platformSuggestedFilename() const
- {
- return filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition));
- }
+ static bool isAppendableHeader(const String &key);
+ String platformSuggestedFilename() const;
+ void setStatusLine(const String&);
+
bool m_responseFired;
};
Added: trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp (0 => 222012)
--- trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp 2017-09-14 06:57:12 UTC (rev 222012)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(CURL)
+#include "ResourceResponse.h"
+
+#include "HTTPParsers.h"
+
+namespace WebCore {
+
+bool ResourceResponse::isAppendableHeader(const String &key)
+{
+ static const char* appendableHeaders[] = {
+ "access-control-allow-headers",
+ "access-control-allow-methods",
+ "access-control-allow-origin",
+ "access-control-expose-headers",
+ "allow",
+ "cache-control",
+ "connection",
+ "content-encoding",
+ "content-language",
+ "if-match",
+ "if-none-match",
+ "keep-alive",
+ "pragma",
+ "proxy-authenticate",
+ "public",
+ "server",
+ "set-cookie",
+ "te",
+ "trailer",
+ "transfer-encoding",
+ "upgrade",
+ "user-agent",
+ "vary",
+ "via",
+ "warning",
+ "www-authenticate"
+ };
+
+ // Custom headers start with 'X-', and need no further checking.
+ if (key.startsWith("x-", /* caseSensitive */ false))
+ return true;
+
+ for (auto& header : appendableHeaders) {
+ if (equalIgnoringASCIICase(key, header))
+ return true;
+ }
+
+ return false;
+}
+
+void ResourceResponse::appendHTTPHeaderField(const String& header)
+{
+ int splitPosistion = header.find(":");
+ if (splitPosistion != notFound) {
+ String key = header.left(splitPosistion).stripWhiteSpace();
+ String value = header.substring(splitPosistion + 1).stripWhiteSpace();
+
+ if (isAppendableHeader(key))
+ addHTTPHeaderField(key, value);
+ else
+ setHTTPHeaderField(key, value);
+ } else if (header.startsWith("HTTP", false)) {
+ // This is the first line of the response.
+ setStatusLine(header);
+ }
+}
+
+void ResourceResponse::setStatusLine(const String& header)
+{
+ String statusLine = header.stripWhiteSpace();
+
+ int httpVersionEndPosition = statusLine.find(" ");
+ int statusCodeEndPosition = notFound;
+
+ // Extract the http version
+ if (httpVersionEndPosition != notFound) {
+ String httpVersion = statusLine.left(httpVersionEndPosition);
+ setHTTPVersion(httpVersion.stripWhiteSpace());
+
+ statusLine = statusLine.substring(httpVersionEndPosition + 1).stripWhiteSpace();
+ statusCodeEndPosition = statusLine.find(" ");
+ }
+
+ // Extract the http status text
+ if (statusCodeEndPosition != notFound) {
+ String statusText = statusLine.substring(statusCodeEndPosition + 1);
+ setHTTPStatusText(statusText.stripWhiteSpace());
+ }
+}
+
+String ResourceResponse::platformSuggestedFilename() const
+{
+ return filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition));
+}
+
+bool ResourceResponse::isRedirection() const
+{
+ auto statusCode = httpStatusCode();
+ return (300 <= statusCode) && (statusCode < 400) && (statusCode != 304);
+}
+
+bool ResourceResponse::isNotModified() const
+{
+ return (httpStatusCode() == 304);
+}
+
+bool ResourceResponse::isUnauthorized() const
+{
+ return (httpStatusCode() == 401);
+}
+
+}
+
+#endif