7 if (0 === strpos(http\Client\Curl\Versions\CURL, "7.64.0") ||
8 0 === strpos(http\Client\Curl\Versions\CURL, "7.88.1")) {
9 die("skip - cookie handling broken or crashes with libcurl v" . http\Client\Curl\Versions\CURL ."\n");
15 include "helper/server.inc";
20 global $tmpfile, $section;
21 printf("# %s\n", $section);
22 foreach (file($tmpfile) as $line) {
23 if ($line[0] === "#" || $line === "\n") {
26 printf("%s:\t%s", $tmpfile, $line);
30 function send_and_check($client, $cmp) {
31 global $section, $request;
32 $client->requeue($request)->send();
33 foreach ($client->getResponse()->getCookies() as $list) {
34 foreach ($list->getCookies() as $name => $value) {
35 if ($cmp[$name] != $value) {
36 printf("# %s\nExpected %s=%s, got %s\n",
37 $section, $name, $cmp[$name], $value);
44 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
45 $request = new http\Client\Request("GET", "http://localhost");
47 $section = "distinct clients";
49 server("cookie.inc", function($port) use($request, $tmpfile) {
50 $request->setOptions(array("port" => $port));
51 $client = new http\Client;
52 send_and_check($client, ["counter" => 1]);
54 server("cookie.inc", function($port) use($request, $tmpfile) {
55 $request->setOptions(array("port" => $port));
56 $client = new http\Client;
57 send_and_check($client, ["counter" => 1]);
59 server("cookie.inc", function($port) use($request, $tmpfile) {
60 $request->setOptions(array("port" => $port));
61 $client = new http\Client;
62 send_and_check($client, ["counter" => 1]);
65 $section = "reusing curl handles";
67 server("cookie.inc", function($port) use($request, $tmpfile) {
68 $request->setOptions(array("port" => $port));
69 $client = new http\Client("curl", "test");
70 send_and_check($client, ["counter" => 1]);
72 server("cookie.inc", function($port) use($request, $tmpfile) {
73 $request->setOptions(array("port" => $port));
74 $client = new http\Client("curl", "test");
75 send_and_check($client, ["counter" => 2]);
77 server("cookie.inc", function($port) use($request, $tmpfile) {
78 $request->setOptions(array("port" => $port));
79 $client = new http\Client("curl", "test");
80 send_and_check($client, ["counter" => 3]);
83 $section = "distict client with persistent cookies";
85 $request->setOptions(array("cookiestore" => $tmpfile));
87 server("cookie.inc", function($port) use($request, $tmpfile) {
88 $request->setOptions(array("port" => $port));
89 $client = new http\Client;
90 send_and_check($client, ["counter" => 1]);
91 send_and_check($client, ["counter" => 2]);
92 send_and_check($client, ["counter" => 3]);
94 server("cookie.inc", function($port) use($request, $tmpfile) {
95 $request->setOptions(array("port" => $port));
96 $client = new http\Client;
97 send_and_check($client, ["counter" => 4]);
98 send_and_check($client, ["counter" => 5]);
99 send_and_check($client, ["counter" => 6]);
102 $section = "distinct client with persistent cookies, but session cookies removed";
104 server("cookie.inc", function($port) use($request, $tmpfile) {
105 $request->setOptions(array("port" => $port, "cookiesession" => true));
106 $client = new http\Client;
107 send_and_check($client, ["counter" => 1]);
108 send_and_check($client, ["counter" => 1]);
109 send_and_check($client, ["counter" => 1]);
112 $section = "distinct client with persistent cookies, and session cookies kept";
114 server("cookie.inc", function($port) use($request, $tmpfile) {
115 $request->setOptions(array("port" => $port, "cookiesession" => false));
116 $client = new http\Client;
117 send_and_check($client, ["counter" => 2]);
118 send_and_check($client, ["counter" => 3]);
119 send_and_check($client, ["counter" => 4]);
122 $section = "reusing curl handles without persistent cookies and disabling cookie_share";
124 $c = new http\Client("curl", "test");
125 $c->configure(array("share_cookies" => false));
127 $request->setOptions(array("cookiestore" => null));
129 server("cookie.inc", function($port) use($request, $tmpfile) {
130 $request->setOptions(array("port" => $port));
131 $client = new http\Client("curl", "test");
132 send_and_check($client, ["counter" => 1]);
134 server("cookie.inc", function($port) use($request, $tmpfile) {
135 $request->setOptions(array("port" => $port));
136 $client = new http\Client("curl", "test");
137 send_and_check($client, ["counter" => 1]);
139 server("cookie.inc", function($port) use($request, $tmpfile) {
140 $request->setOptions(array("port" => $port));
141 $client = new http\Client("curl", "test");
142 send_and_check($client, ["counter" => 1]);