1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
--TEST--
client cookies
--SKIPIF--
<?php
include "skipif.inc";
skip_client_test();
if (0 === strpos(http\Client\Curl\Versions\CURL, "7.64.0") ||
0 === strpos(http\Client\Curl\Versions\CURL, "7.88.1")) {
die("skip - cookie handling broken or crashes with libcurl v" . http\Client\Curl\Versions\CURL ."\n");
}
?>
--FILE--
<?php
include "helper/server.inc";
echo "Test\n";
function dump() {
global $tmpfile, $section;
printf("# %s\n", $section);
foreach (file($tmpfile) as $line) {
if ($line[0] === "#" || $line === "\n") {
continue;
}
printf("%s:\t%s", $tmpfile, $line);
}
}
function send_and_check($client, $cmp) {
global $section, $request;
$client->requeue($request)->send();
foreach ($client->getResponse()->getCookies() as $list) {
foreach ($list->getCookies() as $name => $value) {
if ($cmp[$name] != $value) {
printf("# %s\nExpected %s=%s, got %s\n",
$section, $name, $cmp[$name], $value);
}
}
}
#dump();
}
$tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
$request = new http\Client\Request("GET", "http://localhost");
$section = "distinct clients";
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client;
send_and_check($client, ["counter" => 1]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client;
send_and_check($client, ["counter" => 1]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client;
send_and_check($client, ["counter" => 1]);
});
$section = "reusing curl handles";
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 1]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 2]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 3]);
});
$section = "distict client with persistent cookies";
$request->setOptions(array("cookiestore" => $tmpfile));
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client;
send_and_check($client, ["counter" => 1]);
send_and_check($client, ["counter" => 2]);
send_and_check($client, ["counter" => 3]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client;
send_and_check($client, ["counter" => 4]);
send_and_check($client, ["counter" => 5]);
send_and_check($client, ["counter" => 6]);
});
$section = "distinct client with persistent cookies, but session cookies removed";
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port, "cookiesession" => true));
$client = new http\Client;
send_and_check($client, ["counter" => 1]);
send_and_check($client, ["counter" => 1]);
send_and_check($client, ["counter" => 1]);
});
$section = "distinct client with persistent cookies, and session cookies kept";
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port, "cookiesession" => false));
$client = new http\Client;
send_and_check($client, ["counter" => 2]);
send_and_check($client, ["counter" => 3]);
send_and_check($client, ["counter" => 4]);
});
$section = "reusing curl handles without persistent cookies and disabling cookie_share";
$c = new http\Client("curl", "test");
$c->configure(array("share_cookies" => false));
$c = null;
$request->setOptions(array("cookiestore" => null));
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 1]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 1]);
});
server("cookie.inc", function($port) use($request, $tmpfile) {
$request->setOptions(array("port" => $port));
$client = new http\Client("curl", "test");
send_and_check($client, ["counter" => 1]);
});
unlink($tmpfile);
?>
===DONE===
--EXPECT--
Test
===DONE===
|