11 include "helper/server.inc";
16 global $tmpfile, $section;
17 printf("# %s\n", $section);
18 foreach (file($tmpfile) as $line) {
19 if ($line[0] === "#" || $line === "\n") {
22 printf("%s:\t%s", $tmpfile, $line);
26 function send_and_check($client, $cmp) {
27 global $section, $request;
28 $client->requeue($request)->send();
29 foreach ($client->getResponse()->getCookies() as $list) {
30 foreach ($list->getCookies() as $name => $value) {
31 if ($cmp[$name] != $value) {
32 printf("# %s\nExpected %s=%s, got %s\n",
33 $section, $name, $cmp[$name], $value);
40 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
41 $request = new http\Client\Request("GET", "http://localhost");
43 $section = "distinct clients";
45 server("cookie.inc", function($port) use($request, $tmpfile) {
46 $request->setOptions(array("port" => $port));
47 $client = new http\Client;
48 send_and_check($client, ["counter" => 1]);
50 server("cookie.inc", function($port) use($request, $tmpfile) {
51 $request->setOptions(array("port" => $port));
52 $client = new http\Client;
53 send_and_check($client, ["counter" => 1]);
55 server("cookie.inc", function($port) use($request, $tmpfile) {
56 $request->setOptions(array("port" => $port));
57 $client = new http\Client;
58 send_and_check($client, ["counter" => 1]);
61 $section = "reusing curl handles";
63 server("cookie.inc", function($port) use($request, $tmpfile) {
64 $request->setOptions(array("port" => $port));
65 $client = new http\Client("curl", "test");
66 send_and_check($client, ["counter" => 1]);
68 server("cookie.inc", function($port) use($request, $tmpfile) {
69 $request->setOptions(array("port" => $port));
70 $client = new http\Client("curl", "test");
71 send_and_check($client, ["counter" => 2]);
73 server("cookie.inc", function($port) use($request, $tmpfile) {
74 $request->setOptions(array("port" => $port));
75 $client = new http\Client("curl", "test");
76 send_and_check($client, ["counter" => 3]);
79 $section = "distict client with persistent cookies";
81 $request->setOptions(array("cookiestore" => $tmpfile));
83 server("cookie.inc", function($port) use($request, $tmpfile) {
84 $request->setOptions(array("port" => $port));
85 $client = new http\Client;
86 send_and_check($client, ["counter" => 1]);
87 send_and_check($client, ["counter" => 2]);
88 send_and_check($client, ["counter" => 3]);
90 server("cookie.inc", function($port) use($request, $tmpfile) {
91 $request->setOptions(array("port" => $port));
92 $client = new http\Client;
93 send_and_check($client, ["counter" => 4]);
94 send_and_check($client, ["counter" => 5]);
95 send_and_check($client, ["counter" => 6]);
98 $section = "distinct client with persistent cookies, but session cookies removed";
100 server("cookie.inc", function($port) use($request, $tmpfile) {
101 $request->setOptions(array("port" => $port, "cookiesession" => true));
102 $client = new http\Client;
103 send_and_check($client, ["counter" => 1]);
104 send_and_check($client, ["counter" => 1]);
105 send_and_check($client, ["counter" => 1]);
108 $section = "distinct client with persistent cookies, and session cookies kept";
110 server("cookie.inc", function($port) use($request, $tmpfile) {
111 $request->setOptions(array("port" => $port, "cookiesession" => false));
112 $client = new http\Client;
113 send_and_check($client, ["counter" => 2]);
114 send_and_check($client, ["counter" => 3]);
115 send_and_check($client, ["counter" => 4]);
118 $section = "reusing curl handles without persistent cookies and disabling cookie_share";
120 $c = new http\Client("curl", "test");
121 $c->configure(array("share_cookies" => false));
123 $request->setOptions(array("cookiestore" => null));
125 server("cookie.inc", function($port) use($request, $tmpfile) {
126 $request->setOptions(array("port" => $port));
127 $client = new http\Client("curl", "test");
128 send_and_check($client, ["counter" => 1]);
130 server("cookie.inc", function($port) use($request, $tmpfile) {
131 $request->setOptions(array("port" => $port));
132 $client = new http\Client("curl", "test");
133 send_and_check($client, ["counter" => 1]);
135 server("cookie.inc", function($port) use($request, $tmpfile) {
136 $request->setOptions(array("port" => $port));
137 $client = new http\Client("curl", "test");
138 send_and_check($client, ["counter" => 1]);