[Curl] Surface additional NetworkLoadMetrics
authordon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Aug 2018 01:12:05 +0000 (01:12 +0000)
committerdon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Aug 2018 01:12:05 +0000 (01:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188391

Reviewed by Joseph Pecoraro.

Source/WebCore:

* platform/network/curl/CurlContext.cpp:
(WebCore::CurlHandle::getNetworkLoadMetrics):

Source/WebKit:

* NetworkProcess/curl/NetworkDataTaskCurl.cpp:
(WebKit::NetworkDataTaskCurl::curlDidReceiveResponse):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/curl/CurlContext.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp

index 1a7de65..e33db1b 100644 (file)
@@ -1,5 +1,15 @@
 2018-08-08  Don Olmstead  <don.olmstead@sony.com>
 
+        [Curl] Surface additional NetworkLoadMetrics
+        https://bugs.webkit.org/show_bug.cgi?id=188391
+
+        Reviewed by Joseph Pecoraro.
+
+        * platform/network/curl/CurlContext.cpp:
+        (WebCore::CurlHandle::getNetworkLoadMetrics):
+
+2018-08-08  Don Olmstead  <don.olmstead@sony.com>
+
         [Nicosia] Add the Nicosia-specific PlatformLayer type alias
         https://bugs.webkit.org/show_bug.cgi?id=188405
         <rdar://problem/43039520>
index 166ee38..2c28b62 100644 (file)
@@ -77,6 +77,11 @@ constexpr const char* EnvironmentVariableReader::sscanTemplate<signed>() { retur
 template<>
 constexpr const char* EnvironmentVariableReader::sscanTemplate<unsigned>() { return "%u"; }
 
+// ALPN Protocol ID (RFC7301) https://tools.ietf.org/html/rfc7301
+static const ASCIILiteral httpVersion10 { "http/1.0"_s };
+static const ASCIILiteral httpVersion11 { "http/1.1"_s };
+static const ASCIILiteral httpVersion2 { "h2"_s };
+
 // CurlContext -------------------------------------------------------------------
 
 CurlContext& CurlContext::singleton()
@@ -725,6 +730,13 @@ std::optional<NetworkLoadMetrics> CurlHandle::getNetworkLoadMetrics()
     double connect = 0.0;
     double appConnect = 0.0;
     double startTransfer = 0.0;
+    long requestHeaderSize = 0;
+    curl_off_t requestBodySize = 0;
+    long responseHeaderSize = 0;
+    curl_off_t responseBodySize = 0;
+    long version = 0;
+    char* ip = nullptr;
+    long port = 0;
 
     if (!m_handle)
         return std::nullopt;
@@ -745,6 +757,35 @@ std::optional<NetworkLoadMetrics> CurlHandle::getNetworkLoadMetrics()
     if (errorCode != CURLE_OK)
         return std::nullopt;
 
+    // FIXME: Gets total request size not just headers https://bugs.webkit.org/show_bug.cgi?id=188363
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_REQUEST_SIZE, &requestHeaderSize);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_SIZE_UPLOAD_T, &requestBodySize);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_HEADER_SIZE, &responseHeaderSize);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_SIZE_DOWNLOAD_T, &responseBodySize);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_IP, &ip);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_PORT, &port);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
+    errorCode = curl_easy_getinfo(m_handle, CURLINFO_HTTP_VERSION, &version);
+    if (errorCode != CURLE_OK)
+        return std::nullopt;
+
     NetworkLoadMetrics networkLoadMetrics;
 
     networkLoadMetrics.domainLookupStart = Seconds(0);
@@ -760,6 +801,24 @@ std::optional<NetworkLoadMetrics> CurlHandle::getNetworkLoadMetrics()
     networkLoadMetrics.requestStart = networkLoadMetrics.connectEnd;
     networkLoadMetrics.responseStart = Seconds(startTransfer);
 
+    networkLoadMetrics.requestHeaderBytesSent = requestHeaderSize;
+    networkLoadMetrics.requestBodyBytesSent = requestBodySize;
+    networkLoadMetrics.responseHeaderBytesReceived = responseHeaderSize;
+    networkLoadMetrics.responseBodyBytesReceived = responseBodySize;
+
+    if (ip) {
+        networkLoadMetrics.remoteAddress = String(ip);
+        if (port)
+            networkLoadMetrics.remoteAddress.append(":" + String::number(port));
+    }
+
+    if (version == CURL_HTTP_VERSION_1_0)
+        networkLoadMetrics.protocol = httpVersion10;
+    else if (version == CURL_HTTP_VERSION_1_1)
+        networkLoadMetrics.protocol = httpVersion11;
+    else if (version == CURL_HTTP_VERSION_2)
+        networkLoadMetrics.protocol = httpVersion2;
+
     return networkLoadMetrics;
 }
 
index c463d1c..9502b57 100644 (file)
@@ -1,3 +1,13 @@
+2018-08-08  Don Olmstead  <don.olmstead@sony.com>
+
+        [Curl] Surface additional NetworkLoadMetrics
+        https://bugs.webkit.org/show_bug.cgi?id=188391
+
+        Reviewed by Joseph Pecoraro.
+
+        * NetworkProcess/curl/NetworkDataTaskCurl.cpp:
+        (WebKit::NetworkDataTaskCurl::curlDidReceiveResponse):
+
 2018-08-08  Alex Christensen  <achristensen@webkit.org>
 
         Fix possible null dereference in WebBackForwardList::restoreFromState
index fbc89df..e7c487f 100644 (file)
@@ -147,13 +147,14 @@ void NetworkDataTaskCurl::curlDidSendData(CurlRequest&, unsigned long long total
     m_client->didSendData(totalBytesSent, totalBytesExpectedToSend);
 }
 
-void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest&, const CurlResponse& receivedResponse)
+void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest& request, const CurlResponse& receivedResponse)
 {
     auto protectedThis = makeRef(*this);
     if (state() == State::Canceling || state() == State::Completed || !m_client)
         return;
 
     m_response = ResourceResponse(receivedResponse);
+    m_response.setDeprecatedNetworkLoadMetrics(request.networkLoadMetrics().isolatedCopy());
 
     handleCookieHeaders(receivedResponse);