tests & bugfixes
[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 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty.txt"));
47 echo $m;
48 var_dump(
49 $m->getHttpVersion(),
50 $m->getType()==HttpMessage::TYPE_RESPONSE,
51 $m->getResponseCode(),
52 $m->getResponseStatus(),
53 $m->getHeaders()
54 );
55 echo $m->getParentMessage();
56
57 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty_gzip.txt"));
58 echo $m;
59 var_dump(
60 $m->getHttpVersion(),
61 $m->getType()==HttpMessage::TYPE_RESPONSE,
62 $m->getResponseCode(),
63 $m->getResponseStatus(),
64 $m->getHeaders()
65 );
66 echo $m->getParentMessage();
67
68 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_empty_chunked.txt"));
69 echo $m;
70 var_dump(
71 $m->getHttpVersion(),
72 $m->getType()==HttpMessage::TYPE_RESPONSE,
73 $m->getResponseCode(),
74 $m->getResponseStatus(),
75 $m->getHeaders()
76 );
77 echo $m->getParentMessage();
78
79 $m = new HttpMessage(file_get_contents(__DIR__."/data/message_rr_helloworld_chunked.txt"));
80 echo $m;
81 var_dump(
82 $m->getHttpVersion(),
83 $m->getType()==HttpMessage::TYPE_RESPONSE,
84 $m->getResponseCode(),
85 $m->getResponseStatus(),
86 $m->getHeaders()
87 );
88 echo $m->getParentMessage();
89
90 echo "Done\n";
91 --EXPECTF--
92 Test
93 string(3) "0.0"
94 bool(true)
95 array(0) {
96 }
97 GET / HTTP/1.1
98 string(3) "1.1"
99 bool(true)
100 string(3) "GET"
101 string(1) "/"
102 array(0) {
103 }
104 HTTP/1.1 200 Okidoki
105 string(3) "1.1"
106 bool(true)
107 int(200)
108 string(7) "Okidoki"
109 array(0) {
110 }
111 HTTP/1.1 200 OK
112 Date: Wed, 25 Aug 2010 12:11:44 GMT
113 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
114 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
115 Etag: "2002a-0-48549d615a35c"
116 Accept-Ranges: bytes
117 Content-Length: 0
118 Vary: Accept-Encoding
119 Connection: close
120 Content-Type: text/plain
121 X-Original-Content-Length: 0
122 string(3) "1.1"
123 bool(true)
124 int(200)
125 string(2) "OK"
126 array(10) {
127 ["Date"]=>
128 string(29) "Wed, 25 Aug 2010 12:11:44 GMT"
129 ["Server"]=>
130 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
131 ["Last-Modified"]=>
132 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
133 ["Etag"]=>
134 string(23) ""2002a-0-48549d615a35c""
135 ["Accept-Ranges"]=>
136 string(5) "bytes"
137 ["Content-Length"]=>
138 int(0)
139 ["Vary"]=>
140 string(15) "Accept-Encoding"
141 ["Connection"]=>
142 string(5) "close"
143 ["Content-Type"]=>
144 string(10) "text/plain"
145 ["X-Original-Content-Length"]=>
146 string(1) "0"
147 }
148 GET /default/empty.txt HTTP/1.1
149 Host: localhost
150 Connection: close
151 Content-Length: 0
152 HTTP/1.1 200 OK
153 Date: Thu, 26 Aug 2010 09:55:09 GMT
154 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
155 Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT
156 Etag: "2002a-0-48549d615a35c"
157 Accept-Ranges: bytes
158 Vary: Accept-Encoding
159 Content-Length: 0
160 Connection: close
161 Content-Type: text/plain
162 X-Original-Content-Length: 20
163 X-Original-Content-Encoding: gzip
164 string(3) "1.1"
165 bool(true)
166 int(200)
167 string(2) "OK"
168 array(11) {
169 ["Date"]=>
170 string(29) "Thu, 26 Aug 2010 09:55:09 GMT"
171 ["Server"]=>
172 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
173 ["Last-Modified"]=>
174 string(29) "Wed, 28 Apr 2010 10:54:37 GMT"
175 ["Etag"]=>
176 string(23) ""2002a-0-48549d615a35c""
177 ["Accept-Ranges"]=>
178 string(5) "bytes"
179 ["Vary"]=>
180 string(15) "Accept-Encoding"
181 ["Content-Length"]=>
182 int(0)
183 ["Connection"]=>
184 string(5) "close"
185 ["Content-Type"]=>
186 string(10) "text/plain"
187 ["X-Original-Content-Length"]=>
188 string(2) "20"
189 ["X-Original-Content-Encoding"]=>
190 string(4) "gzip"
191 }
192 GET /default/empty.txt HTTP/1.1
193 Host: localhost
194 Accept-Encoding: gzip
195 Connection: close
196 Content-Length: 0
197 HTTP/1.1 200 OK
198 Date: Thu, 26 Aug 2010 11:41:02 GMT
199 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
200 X-Powered-By: PHP/5.3.3
201 Vary: Accept-Encoding
202 Connection: close
203 Content-Type: text/html
204 X-Original-Transfer-Encoding: chunked
205 Content-Length: 0
206 string(3) "1.1"
207 bool(true)
208 int(200)
209 string(2) "OK"
210 array(8) {
211 ["Date"]=>
212 string(29) "Thu, 26 Aug 2010 11:41:02 GMT"
213 ["Server"]=>
214 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
215 ["X-Powered-By"]=>
216 string(9) "PHP/5.3.3"
217 ["Vary"]=>
218 string(15) "Accept-Encoding"
219 ["Connection"]=>
220 string(5) "close"
221 ["Content-Type"]=>
222 string(9) "text/html"
223 ["X-Original-Transfer-Encoding"]=>
224 string(7) "chunked"
225 ["Content-Length"]=>
226 int(0)
227 }
228 GET /default/empty.php HTTP/1.1
229 Connection: close
230 Host: localhost
231 Content-Length: 0
232 HTTP/1.1 200 OK
233 Date: Thu, 26 Aug 2010 12:51:28 GMT
234 Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6
235 Vary: Accept-Encoding
236 Connection: close
237 Content-Type: text/plain
238 X-Original-Transfer-Encoding: chunked
239 Content-Length: 14
240
241 Hello, World!
242
243 string(3) "1.1"
244 bool(true)
245 int(200)
246 string(2) "OK"
247 array(7) {
248 ["Date"]=>
249 string(29) "Thu, 26 Aug 2010 12:51:28 GMT"
250 ["Server"]=>
251 string(68) "Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6"
252 ["Vary"]=>
253 string(15) "Accept-Encoding"
254 ["Connection"]=>
255 string(5) "close"
256 ["Content-Type"]=>
257 string(10) "text/plain"
258 ["X-Original-Transfer-Encoding"]=>
259 string(7) "chunked"
260 ["Content-Length"]=>
261 int(14)
262 }
263 GET /cgi-bin/chunked.sh HTTP/1.1
264 Host: localhost
265 Connection: close
266 Content-Length: 0
267 Done