Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: LayoutTests/http/tests/navigation/resources/save-beacon.php

Issue 232053005: Implement navigator.sendBeacon() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adjust unrelated test expectation Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/navigation/resources/save-beacon.php
diff --git a/LayoutTests/http/tests/navigation/resources/save-beacon.php b/LayoutTests/http/tests/navigation/resources/save-beacon.php
new file mode 100644
index 0000000000000000000000000000000000000000..4de21933b06342f08ef3112b5617b9f776de0be1
--- /dev/null
+++ b/LayoutTests/http/tests/navigation/resources/save-beacon.php
@@ -0,0 +1,35 @@
+<?php
+function prettify($name) {
+ return str_replace(' ', '-', ucwords(str_replace('_', ' ', str_replace('http_', '', strtolower($name)))));
+}
+
+$beaconFilename = "beacon" . (isset($_REQUEST['name']) ? $_REQUEST['name'] : "") . ".txt";
+$beaconFile = fopen($beaconFilename . ".tmp", 'w');
+$httpHeaders = $_SERVER;
+ksort($httpHeaders, SORT_STRING);
+$contentType = "";
+foreach ($httpHeaders as $name => $value) {
+ if ($name === "CONTENT_TYPE" || $name === "HTTP_REFERER" || $name === "REQUEST_METHOD" || $name === "HTTP_COOKIE" || $name === "HTTP_ORIGIN") {
+ if ($name === "CONTENT_TYPE") {
+ $contentType = $value;
+ $value = preg_replace('/boundary=.*$/', '', $value);
+ }
+ $headerName = prettify($name);
+ fwrite($beaconFile, "$headerName: $value\n");
+ }
+}
+$postdata = file_get_contents("php://input");
+if (strlen($postdata) == 0)
+ $postdata = http_build_query($_POST);
+
+fwrite($beaconFile, "Length: " . strlen($postdata) . "\n");
+if (strpos($contentType, "application/") !== false) {
+ $postdata = base64_encode($postdata);
+}
+
+fwrite($beaconFile, "Body: $postdata\n");
+fclose($beaconFile);
+rename($beaconFilename . ".tmp", $beaconFilename);
+foreach ($_COOKIE as $name => $value)
+ setcookie($name, "deleted", time() - 60, "/");
+?>

Powered by Google App Engine
This is Rietveld 408576698