Skip to content
Permalink
Browse files
[Curl] Add timeout support to XMLHttpRequest
https://bugs.webkit.org/show_bug.cgi?id=181876

Patch by Basuke Suzuki <Basuke.Suzuki@sony.com> on 2018-01-19
Reviewed by Alex Christensen

* platform/network/ResourceRequestBase.cpp:
* platform/network/curl/CurlContext.cpp:
(WebCore::CurlHandle::setTimeout):
* platform/network/curl/CurlContext.h:
* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::setupTransfer):
(WebCore::CurlRequest::didCompleteTransfer):
* platform/network/curl/ResourceError.h:
* platform/network/curl/ResourceErrorCurl.cpp:
(WebCore::ResourceError::httpError):

Canonical link: https://commits.webkit.org/197713@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227237 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
basuke authored and webkit-commit-queue committed Jan 19, 2018
1 parent b564d23 commit e91bf7894e98312198193fb799db3c071d6b0bbf
Showing 7 changed files with 33 additions and 5 deletions.
@@ -1,3 +1,21 @@
2018-01-19 Basuke Suzuki <Basuke.Suzuki@sony.com>

[Curl] Add timeout support to XMLHttpRequest
https://bugs.webkit.org/show_bug.cgi?id=181876

Reviewed by Alex Christensen

* platform/network/ResourceRequestBase.cpp:
* platform/network/curl/CurlContext.cpp:
(WebCore::CurlHandle::setTimeout):
* platform/network/curl/CurlContext.h:
* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::setupTransfer):
(WebCore::CurlRequest::didCompleteTransfer):
* platform/network/curl/ResourceError.h:
* platform/network/curl/ResourceErrorCurl.cpp:
(WebCore::ResourceError::httpError):

2018-01-19 Yoav Weiss <yoav@yoav.ws>

Support for preconnect Link headers
@@ -33,7 +33,7 @@

namespace WebCore {

#if !USE(SOUP) && (!PLATFORM(MAC) || USE(CFURLCONNECTION))
#if PLATFORM(IOS) || USE(CFURLCONNECTION)
double ResourceRequestBase::s_defaultTimeoutInterval = INT_MAX;
#else
// Will use NSURLRequest default timeout unless set to a non-zero value with setDefaultTimeoutInterval().
@@ -520,6 +520,11 @@ void CurlHandle::enableTimeout()
curl_easy_setopt(m_handle, CURLOPT_DNS_CACHE_TIMEOUT, dnsCacheTimeout);
}

void CurlHandle::setTimeout(long timeoutMilliseconds)
{
curl_easy_setopt(m_handle, CURLOPT_TIMEOUT_MS, timeoutMilliseconds);
}

void CurlHandle::setHeaderCallbackFunction(curl_write_callback callbackFunc, void* userData)
{
curl_easy_setopt(m_handle, CURLOPT_HEADERFUNCTION, callbackFunc);
@@ -263,6 +263,7 @@ class CurlHandle {
void enableProxyIfExists();

void enableTimeout();
void setTimeout(long timeoutMilliseconds);

// Callback function
void setHeaderCallbackFunction(curl_write_callback, void*);
@@ -192,6 +192,9 @@ CURL* CurlRequest::setupTransfer()
m_curlHandle->enableAcceptEncoding();
m_curlHandle->enableTimeout();

long timeoutMilliseconds = (m_request.timeoutInterval() > 0.0) ? static_cast<long>(m_request.timeoutInterval() * 1000.0) : 0;
m_curlHandle->setTimeout(timeoutMilliseconds);

m_curlHandle->enableProxyIfExists();
m_curlHandle->enableCookieJarIfExists();

@@ -421,7 +424,8 @@ void CurlRequest::didCompleteTransfer(CURLcode result)
});
}
} else {
auto resourceError = ResourceError::httpError(result, m_request.url());
auto type = (result == CURLE_OPERATION_TIMEDOUT && m_request.timeoutInterval() > 0.0) ? ResourceError::Type::Timeout : ResourceError::Type::General;
auto resourceError = ResourceError::httpError(result, m_request.url(), type);
if (m_sslVerifier.sslErrors())
resourceError.setSslErrors(m_sslVerifier.sslErrors());

@@ -44,7 +44,7 @@ class ResourceError : public ResourceErrorBase {
{
}

static ResourceError httpError(int errorCode, const URL& failingURL);
static ResourceError httpError(int errorCode, const URL& failingURL, Type = Type::General);
static ResourceError sslError(int errorCode, unsigned sslErrors, const URL& failingURL);

unsigned sslErrors() const { return m_sslErrors; }
@@ -34,9 +34,9 @@ namespace WebCore {

const char* const ResourceError::curlErrorDomain = "CurlErrorDomain";

ResourceError ResourceError::httpError(int errorCode, const URL& failingURL)
ResourceError ResourceError::httpError(int errorCode, const URL& failingURL, Type type)
{
return ResourceError(curlErrorDomain, errorCode, failingURL, CurlHandle::errorDescription(static_cast<CURLcode>(errorCode)));
return ResourceError(curlErrorDomain, errorCode, failingURL, CurlHandle::errorDescription(static_cast<CURLcode>(errorCode)), type);
}

ResourceError ResourceError::sslError(int errorCode, unsigned sslErrors, const URL& failingURL)

0 comments on commit e91bf78

Please sign in to comment.