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

Side by Side 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: Revert CSP checking on redirects Created 6 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 <?php
2 function prettify($name) {
3 return str_replace(' ', '-', ucwords(str_replace('_', ' ', str_replace('http_ ', '', strtolower($name)))));
4 }
5
6 $beaconFilename = "beacon" . (isset($_REQUEST['name']) ? $_REQUEST['name'] : "") . ".txt";
7 $beaconFile = fopen($beaconFilename . ".tmp", 'w');
8 $httpHeaders = $_SERVER;
9 ksort($httpHeaders, SORT_STRING);
10 $contentType = "";
11 foreach ($httpHeaders as $name => $value) {
12 if ($name === "CONTENT_TYPE" || $name === "HTTP_REFERER" || $name === "REQUE ST_METHOD" || $name === "HTTP_COOKIE" || $name === "HTTP_ORIGIN") {
13 if ($name === "CONTENT_TYPE") {
14 $contentType = $value;
15 $value = preg_replace('/boundary=.*$/', '', $value);
16 }
17 $headerName = prettify($name);
18 fwrite($beaconFile, "$headerName: $value\n");
19 }
20 }
21 $postdata = file_get_contents("php://input");
22 if (strlen($postdata) == 0)
23 $postdata = http_build_query($_POST);
24
25 fwrite($beaconFile, "Length: " . strlen($postdata) . "\n");
26 if (strpos($contentType, "application/") !== false) {
27 $postdata = base64_encode($postdata);
28 }
29
30 fwrite($beaconFile, "Body: $postdata\n");
31 fclose($beaconFile);
32 rename($beaconFilename . ".tmp", $beaconFilename);
33 foreach ($_COOKIE as $name => $value)
34 setcookie($name, "deleted", time() - 60, "/");
35 ?>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698