Title: [258004] trunk/Tools
Revision
258004
Author
achristen...@apple.com
Date
2020-03-06 10:26:35 -0800 (Fri, 06 Mar 2020)

Log Message

Fix ResourceLoadDelegate.LoadInfo API test after r257816
https://bugs.webkit.org/show_bug.cgi?id=208550

* TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::HTTPServer::respondToRequests):
Sometimes we need a separate read to read the HTTP body after a request header, sometimes it comes in the same read.
If it comes in the same read, send the response immediately.  Otherwise read the HTTP body then send the response.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (258003 => 258004)


--- trunk/Tools/ChangeLog	2020-03-06 18:19:12 UTC (rev 258003)
+++ trunk/Tools/ChangeLog	2020-03-06 18:26:35 UTC (rev 258004)
@@ -1,3 +1,13 @@
+2020-03-06  Alex Christensen  <achristen...@webkit.org>
+
+        Fix ResourceLoadDelegate.LoadInfo API test after r257816
+        https://bugs.webkit.org/show_bug.cgi?id=208550
+
+        * TestWebKitAPI/cocoa/HTTPServer.mm:
+        (TestWebKitAPI::HTTPServer::respondToRequests):
+        Sometimes we need a separate read to read the HTTP body after a request header, sometimes it comes in the same read.
+        If it comes in the same read, send the response immediately.  Otherwise read the HTTP body then send the response.
+
 2020-03-06  Lauro Moura <lmo...@igalia.com>
 
         [WPE][WebDriver] MiniBrowser should react to close session commands

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (258003 => 258004)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2020-03-06 18:19:12 UTC (rev 258003)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2020-03-06 18:26:35 UTC (rev 258004)
@@ -98,7 +98,7 @@
             request.append(static_cast<const char*>(buffer), size);
             return true;
         });
-        request.append(0);
+        request.append('\0');
 
         const char* getPathPrefix = "GET ";
         const char* postPathPrefix = "POST ";
@@ -105,7 +105,8 @@
         const char* pathSuffix = " HTTP/1.1\r\n";
         const char* pathEnd = strstr(request.data(), pathSuffix);
         ASSERT_WITH_MESSAGE(pathEnd, "HTTPServer assumes request is HTTP 1.1");
-        ASSERT_WITH_MESSAGE(strstr(request.data(), "\r\n\r\n"), "HTTPServer assumes entire HTTP request is received at once");
+        const char* doubleNewline = strstr(request.data(), "\r\n\r\n");
+        ASSERT_WITH_MESSAGE(doubleNewline, "HTTPServer assumes entire HTTP request is received at once");
         size_t pathPrefixLength = 0;
         if (!memcmp(request.data(), getPathPrefix, strlen(getPathPrefix)))
             pathPrefixLength = strlen(getPathPrefix);
@@ -144,14 +145,20 @@
             });
         };
 
-        if (strstr(request.data(), "Content-Length")) {
-            nw_connection_receive(connection, 1, std::numeric_limits<uint32_t>::max(), makeBlockPtr([sendResponse = WTFMove(sendResponse)] (dispatch_data_t content, nw_content_context_t context, bool complete, nw_error_t error) mutable {
-                if (error || !content)
-                    return;
-                sendResponse();
-            }).get());
-        } else
-            sendResponse();
+        if (auto* contentLengthBegin = strstr(request.data(), "Content-Length")) {
+            size_t contentLength = atoi(contentLengthBegin + strlen("Content-Length: "));
+            size_t headerLength = doubleNewline - request.data() + strlen("\r\n\r\n");
+            constexpr size_t nullTerminationLength = 1;
+            if (request.size() - nullTerminationLength - headerLength < contentLength) {
+                nw_connection_receive(connection, 1, std::numeric_limits<uint32_t>::max(), makeBlockPtr([sendResponse = WTFMove(sendResponse)] (dispatch_data_t content, nw_content_context_t context, bool complete, nw_error_t error) mutable {
+                    if (error || !content)
+                        return;
+                    sendResponse();
+                }).get());
+                return;
+            }
+        }
+        sendResponse();
     });
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to