add CURLINFO_RETRY_AFTER
[m6w6/ext-http] / tests / client021.phpt
1 --TEST--
2 client cookies
3 --SKIPIF--
4 <?php
5 include "skipif.inc";
6 skip_client_test();
7 ?>
8 --FILE--
9 <?php
10
11 include "helper/server.inc";
12
13 echo "Test\n";
14
15 function dump() {
16 global $tmpfile, $section;
17 printf("# %s\n", $section);
18 foreach (file($tmpfile) as $line) {
19 if ($line[0] === "#" || $line === "\n") {
20 continue;
21 }
22 printf("%s:\t%s", $tmpfile, $line);
23 }
24 }
25
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);
34 }
35 }
36 }
37 #dump();
38 }
39
40 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
41 $request = new http\Client\Request("GET", "http://localhost");
42
43 $section = "distinct clients";
44
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]);
49 });
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]);
54 });
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]);
59 });
60
61 $section = "reusing curl handles";
62
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]);
67 });
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]);
72 });
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]);
77 });
78
79 $section = "distict client with persistent cookies";
80
81 $request->setOptions(array("cookiestore" => $tmpfile));
82
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]);
89 });
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]);
96 });
97
98 $section = "distinct client with persistent cookies, but session cookies removed";
99
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]);
106 });
107
108 $section = "distinct client with persistent cookies, and session cookies kept";
109
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]);
116 });
117
118 $section = "reusing curl handles without persistent cookies and disabling cookie_share";
119
120 $c = new http\Client("curl", "test");
121 $c->configure(array("share_cookies" => false));
122 $c = null;
123 $request->setOptions(array("cookiestore" => null));
124
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]);
129 });
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]);
134 });
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]);
139 });
140
141
142 unlink($tmpfile);
143
144 ?>
145 ===DONE===
146 --EXPECT--
147 Test
148 ===DONE===