7 if (0 === strpos(http\Client\Curl\Versions\CURL, "7.64.0")) {
8 die("skip - cookie handling broken or crashes with libcurl-7.64\n");
14 include "helper/server.inc";
19 global $tmpfile, $section;
20 printf("# %s\n", $section);
21 foreach (file($tmpfile) as $line) {
22 if ($line[0] === "#" || $line === "\n") {
25 printf("%s:\t%s", $tmpfile, $line);
29 function send_and_check($client, $cmp) {
30 global $section, $request;
31 $client->requeue($request)->send();
32 foreach ($client->getResponse()->getCookies() as $list) {
33 foreach ($list->getCookies() as $name => $value) {
34 if ($cmp[$name] != $value) {
35 printf("# %s\nExpected %s=%s, got %s\n",
36 $section, $name, $cmp[$name], $value);
43 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
44 $request = new http\Client\Request("GET", "http://localhost");
46 $section = "distinct clients";
48 server("cookie.inc", function($port) use($request, $tmpfile) {
49 $request->setOptions(array("port" => $port));
50 $client = new http\Client;
51 send_and_check($client, ["counter" => 1]);
53 server("cookie.inc", function($port) use($request, $tmpfile) {
54 $request->setOptions(array("port" => $port));
55 $client = new http\Client;
56 send_and_check($client, ["counter" => 1]);
58 server("cookie.inc", function($port) use($request, $tmpfile) {
59 $request->setOptions(array("port" => $port));
60 $client = new http\Client;
61 send_and_check($client, ["counter" => 1]);
64 $section = "reusing curl handles";
66 server("cookie.inc", function($port) use($request, $tmpfile) {
67 $request->setOptions(array("port" => $port));
68 $client = new http\Client("curl", "test");
69 send_and_check($client, ["counter" => 1]);
71 server("cookie.inc", function($port) use($request, $tmpfile) {
72 $request->setOptions(array("port" => $port));
73 $client = new http\Client("curl", "test");
74 send_and_check($client, ["counter" => 2]);
76 server("cookie.inc", function($port) use($request, $tmpfile) {
77 $request->setOptions(array("port" => $port));
78 $client = new http\Client("curl", "test");
79 send_and_check($client, ["counter" => 3]);
82 $section = "distict client with persistent cookies";
84 $request->setOptions(array("cookiestore" => $tmpfile));
86 server("cookie.inc", function($port) use($request, $tmpfile) {
87 $request->setOptions(array("port" => $port));
88 $client = new http\Client;
89 send_and_check($client, ["counter" => 1]);
90 send_and_check($client, ["counter" => 2]);
91 send_and_check($client, ["counter" => 3]);
93 server("cookie.inc", function($port) use($request, $tmpfile) {
94 $request->setOptions(array("port" => $port));
95 $client = new http\Client;
96 send_and_check($client, ["counter" => 4]);
97 send_and_check($client, ["counter" => 5]);
98 send_and_check($client, ["counter" => 6]);
101 $section = "distinct client with persistent cookies, but session cookies removed";
103 server("cookie.inc", function($port) use($request, $tmpfile) {
104 $request->setOptions(array("port" => $port, "cookiesession" => true));
105 $client = new http\Client;
106 send_and_check($client, ["counter" => 1]);
107 send_and_check($client, ["counter" => 1]);
108 send_and_check($client, ["counter" => 1]);
111 $section = "distinct client with persistent cookies, and session cookies kept";
113 server("cookie.inc", function($port) use($request, $tmpfile) {
114 $request->setOptions(array("port" => $port, "cookiesession" => false));
115 $client = new http\Client;
116 send_and_check($client, ["counter" => 2]);
117 send_and_check($client, ["counter" => 3]);
118 send_and_check($client, ["counter" => 4]);
121 $section = "reusing curl handles without persistent cookies and disabling cookie_share";
123 $c = new http\Client("curl", "test");
124 $c->configure(array("share_cookies" => false));
126 $request->setOptions(array("cookiestore" => null));
128 server("cookie.inc", function($port) use($request, $tmpfile) {
129 $request->setOptions(array("port" => $port));
130 $client = new http\Client("curl", "test");
131 send_and_check($client, ["counter" => 1]);
133 server("cookie.inc", function($port) use($request, $tmpfile) {
134 $request->setOptions(array("port" => $port));
135 $client = new http\Client("curl", "test");
136 send_and_check($client, ["counter" => 1]);
138 server("cookie.inc", function($port) use($request, $tmpfile) {
139 $request->setOptions(array("port" => $port));
140 $client = new http\Client("curl", "test");
141 send_and_check($client, ["counter" => 1]);