client test and fixes
[m6w6/ext-http] / tests / message001.phpt
1 --TEST--
2 message
3 --SKIPIF--
4 <?php
5 include "skipif.inc";
6 ?>
7 --FILE--
8 <?php
9 echo "Test\n";
10
11 use http\Message as HttpMessage;
12
13 try {
14 echo new HttpMessage(" gosh\n nosh\n ");
15 } catch (Exception $ignore) {
16 }
17
18 $m = new HttpMessage();
19 echo $m;
20 var_dump(
21 $m->getHttpVersion(),
22 $m->getType()==HttpMessage::TYPE_NONE,
23 $m->getHeaders()
24 );
25
26 $m = new HttpMessage("GET / HTTP/1.1\r\n");
27 echo $m;
28 var_dump(
29 $m->getHttpVersion(),
30 $m->getType()==HttpMessage::TYPE_REQUEST,
31 $m->getRequestMethod(),
32 $m->getRequestUrl(),
33 $m->getHeaders()
34 );
35
36 $m = new HttpMessage("HTTP/1.1 200 Okidoki\r\n");
37 echo $m;
38 var_dump(
39 $m->getHttpVersion(),
40 $m->getType()==HttpMessage::TYPE_RESPONSE,
41 $m->getResponseCode(),
42 $m->getResponseStatus(),
43 $m->getHeaders()
44 );
45
46 echo "---\n";
47
48 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty.txt"));
49 echo $m;
50 var_dump(
51 $m->getHttpVersion(),
52 $m->getType()==HttpMessage::TYPE_RESPONSE,
53 $m->getResponseCode(),
54 $m->getResponseStatus(),
55 $m->getHeaders()
56 );
57 echo $m->getParentMessage();
58
59 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty_gzip.txt"));
60 echo $m;
61 var_dump(
62 $m->getHttpVersion(),
63 $m->getType()==HttpMessage::TYPE_RESPONSE,
64 $m->getResponseCode(),
65 $m->getResponseStatus(),
66 $m->getHeaders()
67 );
68 echo $m->getParentMessage();
69
70 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty_chunked.txt"));
71 echo $m;
72 var_dump(
73 $m->getHttpVersion(),
74 $m->getType()==HttpMessage::TYPE_RESPONSE,
75 $m->getResponseCode(),
76 $m->getResponseStatus(),
77 $m->getHeaders()
78 );
79 echo $m->getParentMessage();
80
81 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_helloworld_chunked.txt"));
82 echo $m;
83 var_dump(
84 $m->getHttpVersion(),
85 $m->getType()==HttpMessage::TYPE_RESPONSE,
86 $m->getResponseCode(),
87 $m->getResponseStatus(),
88 $m->getHeaders()
89 );
90 echo $m->getParentMessage();
91
92 echo "---\n";
93
94 $m = new HttpMessage(fopen(__DIR__."/data/message_rr_empty.txt", "r+b"));
95 echo $m;
96 var_dump(
97 $m->getHttpVersion(),
98 $m->getType()==HttpMessage::TYPE_RESPONSE,
99 $m->getResponseCode(),
100 $m->getResponseStatus(),
101 $m->getHeaders()
102 );
103 echo $m->getParentMessage();
104
105 $m = new HttpMessage(fopen(__DIR__."/data/message_rr_empty_gzip.txt", "r+b"));
106 echo $m;
107 var_dump(
108 $m->getHttpVersion(),
109 $m->getType()==HttpMessage::TYPE_RESPONSE,
110 $m->getResponseCode(),
111 $m->getResponseStatus(),
112 $m->getHeaders()
113 );
114 echo $m->getParentMessage();
115
116 $m = new HttpMessage(fopen(__DIR__."/data/message_rr_empty_chunked.txt", "r+b"));
117 echo $m;
118 var_dump(
119 $m->getHttpVersion(),
120 $m->getType()==HttpMessage::TYPE_RESPONSE,
121 $m->getResponseCode(),
122 $m->getResponseStatus(),
123 $m->getHeaders()
124 );
125 echo $m->getParentMessage();
126
127 $m = new HttpMessage(fopen(__DIR__."/data/message_rr_helloworld_chunked.txt", "r+b"));
128 echo $m;
129 var_dump(
130 $m->getHttpVersion(),
131 $m->getType()==HttpMessage::TYPE_RESPONSE,
132 $m->getResponseCode(),
133 $m->getResponseStatus(),
134 $m->getHeaders()
135 );
136 echo $m->getParentMessage();
137
138 echo "Done\n";
139 --EXPECTF--
140 Test
141 string(3) "1.1"
142 bool(true)
143 array(0) {
144 }
145 GET / HTTP/1.1
146 string(3) "1.1"
147 bool(true)
148 string(3) "GET"
149 string(1) "/"
150 array(0) {
151 }
152 HTTP/1.1 200 Okidoki
153 string(3) "1.1"
154 bool(true)
155 int(200)
156 string(7) "Okidoki"
157 array(0) {
158 }
159 ---
160 HTTP/1.1 200 OK
161 Date: Wed, 25 Aug 2010 12:11:44 GMT
162 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
163 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
164 Etag: "2002a-0-48549d615a35c"
165 Accept-Ranges: bytes
166 Content-Length: 0
167 Vary: Accept-Encoding
168 Connection: close
169 Content-Type: text/plain
170 X-Original-Content-Length: 0
171 string(3) "1.1"
172 bool(true)
173 int(200)
174 string(2) "OK"
175 array(10) {
176 ["Date"]=>
177 string(29) "Wed, 25 Aug 2010 12:11:44 GMT"
178 ["Server"]=>
179 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
180 ["Last-Modified"]=>
181 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
182 ["Etag"]=>
183 string(23) ""2002a-0-48549d615a35c""
184 ["Accept-Ranges"]=>
185 string(5) "bytes"
186 ["Content-Length"]=>
187 int(0)
188 ["Vary"]=>
189 string(15) "Accept-Encoding"
190 ["Connection"]=>
191 string(5) "close"
192 ["Content-Type"]=>
193 string(10) "text/plain"
194 ["X-Original-Content-Length"]=>
195 string(1) "0"
196 }
197 GET /default/empty.txt HTTP/1.1
198 Host: localhost
199 Connection: close
200 Content-Length: 0
201 HTTP/1.1 200 OK
202 Date: Thu, 26 Aug 2010 09:55:09 GMT
203 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
204 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
205 Etag: "2002a-0-48549d615a35c"
206 Accept-Ranges: bytes
207 Vary: Accept-Encoding
208 Content-Length: 0
209 Connection: close
210 Content-Type: text/plain
211 X-Original-Content-Length: 20
212 X-Original-Content-Encoding: gzip
213 string(3) "1.1"
214 bool(true)
215 int(200)
216 string(2) "OK"
217 array(11) {
218 ["Date"]=>
219 string(29) "Thu, 26 Aug 2010 09:55:09 GMT"
220 ["Server"]=>
221 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
222 ["Last-Modified"]=>
223 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
224 ["Etag"]=>
225 string(23) ""2002a-0-48549d615a35c""
226 ["Accept-Ranges"]=>
227 string(5) "bytes"
228 ["Vary"]=>
229 string(15) "Accept-Encoding"
230 ["Content-Length"]=>
231 int(0)
232 ["Connection"]=>
233 string(5) "close"
234 ["Content-Type"]=>
235 string(10) "text/plain"
236 ["X-Original-Content-Length"]=>
237 string(2) "20"
238 ["X-Original-Content-Encoding"]=>
239 string(4) "gzip"
240 }
241 GET /default/empty.txt HTTP/1.1
242 Host: localhost
243 Accept-Encoding: gzip
244 Connection: close
245 Content-Length: 0
246 HTTP/1.1 200 OK
247 Date: Thu, 26 Aug 2010 11:41:02 GMT
248 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
249 X-Powered-By: PHP/5.3.3
250 Vary: Accept-Encoding
251 Connection: close
252 Content-Type: text/html
253 X-Original-Transfer-Encoding: chunked
254 Content-Length: 0
255 string(3) "1.1"
256 bool(true)
257 int(200)
258 string(2) "OK"
259 array(8) {
260 ["Date"]=>
261 string(29) "Thu, 26 Aug 2010 11:41:02 GMT"
262 ["Server"]=>
263 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
264 ["X-Powered-By"]=>
265 string(9) "PHP/5.3.3"
266 ["Vary"]=>
267 string(15) "Accept-Encoding"
268 ["Connection"]=>
269 string(5) "close"
270 ["Content-Type"]=>
271 string(9) "text/html"
272 ["X-Original-Transfer-Encoding"]=>
273 string(7) "chunked"
274 ["Content-Length"]=>
275 int(0)
276 }
277 GET /default/empty.php HTTP/1.1
278 Connection: close
279 Host: localhost
280 Content-Length: 0
281 HTTP/1.1 200 OK
282 Date: Thu, 26 Aug 2010 12:51:28 GMT
283 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
284 Vary: Accept-Encoding
285 Connection: close
286 Content-Type: text/plain
287 X-Original-Transfer-Encoding: chunked
288 Content-Length: 14
289
290 Hello, World!
291 string(3) "1.1"
292 bool(true)
293 int(200)
294 string(2) "OK"
295 array(7) {
296 ["Date"]=>
297 string(29) "Thu, 26 Aug 2010 12:51:28 GMT"
298 ["Server"]=>
299 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
300 ["Vary"]=>
301 string(15) "Accept-Encoding"
302 ["Connection"]=>
303 string(5) "close"
304 ["Content-Type"]=>
305 string(10) "text/plain"
306 ["X-Original-Transfer-Encoding"]=>
307 string(7) "chunked"
308 ["Content-Length"]=>
309 int(14)
310 }
311 GET /cgi-bin/chunked.sh HTTP/1.1
312 Host: localhost
313 Connection: close
314 Content-Length: 0
315 ---
316 HTTP/1.1 200 OK
317 Date: Wed, 25 Aug 2010 12:11:44 GMT
318 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
319 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
320 Etag: "2002a-0-48549d615a35c"
321 Accept-Ranges: bytes
322 Content-Length: 0
323 Vary: Accept-Encoding
324 Connection: close
325 Content-Type: text/plain
326 X-Original-Content-Length: 0
327 string(3) "1.1"
328 bool(true)
329 int(200)
330 string(2) "OK"
331 array(10) {
332 ["Date"]=>
333 string(29) "Wed, 25 Aug 2010 12:11:44 GMT"
334 ["Server"]=>
335 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
336 ["Last-Modified"]=>
337 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
338 ["Etag"]=>
339 string(23) ""2002a-0-48549d615a35c""
340 ["Accept-Ranges"]=>
341 string(5) "bytes"
342 ["Content-Length"]=>
343 int(0)
344 ["Vary"]=>
345 string(15) "Accept-Encoding"
346 ["Connection"]=>
347 string(5) "close"
348 ["Content-Type"]=>
349 string(10) "text/plain"
350 ["X-Original-Content-Length"]=>
351 string(1) "0"
352 }
353 GET /default/empty.txt HTTP/1.1
354 Host: localhost
355 Connection: close
356 Content-Length: 0
357 HTTP/1.1 200 OK
358 Date: Thu, 26 Aug 2010 09:55:09 GMT
359 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
360 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
361 Etag: "2002a-0-48549d615a35c"
362 Accept-Ranges: bytes
363 Vary: Accept-Encoding
364 Content-Length: 0
365 Connection: close
366 Content-Type: text/plain
367 X-Original-Content-Length: 20
368 X-Original-Content-Encoding: gzip
369 string(3) "1.1"
370 bool(true)
371 int(200)
372 string(2) "OK"
373 array(11) {
374 ["Date"]=>
375 string(29) "Thu, 26 Aug 2010 09:55:09 GMT"
376 ["Server"]=>
377 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
378 ["Last-Modified"]=>
379 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
380 ["Etag"]=>
381 string(23) ""2002a-0-48549d615a35c""
382 ["Accept-Ranges"]=>
383 string(5) "bytes"
384 ["Vary"]=>
385 string(15) "Accept-Encoding"
386 ["Content-Length"]=>
387 int(0)
388 ["Connection"]=>
389 string(5) "close"
390 ["Content-Type"]=>
391 string(10) "text/plain"
392 ["X-Original-Content-Length"]=>
393 string(2) "20"
394 ["X-Original-Content-Encoding"]=>
395 string(4) "gzip"
396 }
397 GET /default/empty.txt HTTP/1.1
398 Host: localhost
399 Accept-Encoding: gzip
400 Connection: close
401 Content-Length: 0
402 HTTP/1.1 200 OK
403 Date: Thu, 26 Aug 2010 11:41:02 GMT
404 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
405 X-Powered-By: PHP/5.3.3
406 Vary: Accept-Encoding
407 Connection: close
408 Content-Type: text/html
409 X-Original-Transfer-Encoding: chunked
410 Content-Length: 0
411 string(3) "1.1"
412 bool(true)
413 int(200)
414 string(2) "OK"
415 array(8) {
416 ["Date"]=>
417 string(29) "Thu, 26 Aug 2010 11:41:02 GMT"
418 ["Server"]=>
419 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
420 ["X-Powered-By"]=>
421 string(9) "PHP/5.3.3"
422 ["Vary"]=>
423 string(15) "Accept-Encoding"
424 ["Connection"]=>
425 string(5) "close"
426 ["Content-Type"]=>
427 string(9) "text/html"
428 ["X-Original-Transfer-Encoding"]=>
429 string(7) "chunked"
430 ["Content-Length"]=>
431 int(0)
432 }
433 GET /default/empty.php HTTP/1.1
434 Connection: close
435 Host: localhost
436 Content-Length: 0
437 HTTP/1.1 200 OK
438 Date: Thu, 26 Aug 2010 12:51:28 GMT
439 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
440 Vary: Accept-Encoding
441 Connection: close
442 Content-Type: text/plain
443 X-Original-Transfer-Encoding: chunked
444 Content-Length: 14
445
446 Hello, World!
447 string(3) "1.1"
448 bool(true)
449 int(200)
450 string(2) "OK"
451 array(7) {
452 ["Date"]=>
453 string(29) "Thu, 26 Aug 2010 12:51:28 GMT"
454 ["Server"]=>
455 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
456 ["Vary"]=>
457 string(15) "Accept-Encoding"
458 ["Connection"]=>
459 string(5) "close"
460 ["Content-Type"]=>
461 string(10) "text/plain"
462 ["X-Original-Transfer-Encoding"]=>
463 string(7) "chunked"
464 ["Content-Length"]=>
465 int(14)
466 }
467 GET /cgi-bin/chunked.sh HTTP/1.1
468 Host: localhost
469 Connection: close
470 Content-Length: 0
471 Done