OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 #import("dart:isolate"); | 10 #import("dart:isolate"); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 Expect.equals("POST", request.method); | 97 Expect.equals("POST", request.method); |
98 response.contentLength = request.contentLength; | 98 response.contentLength = request.contentLength; |
99 request.inputStream.pipe(response.outputStream); | 99 request.inputStream.pipe(response.outputStream); |
100 } | 100 } |
101 | 101 |
102 // Echo the request content back to the response. | 102 // Echo the request content back to the response. |
103 void _zeroToTenHandler(HttpRequest request, HttpResponse response) { | 103 void _zeroToTenHandler(HttpRequest request, HttpResponse response) { |
104 Expect.equals("GET", request.method); | 104 Expect.equals("GET", request.method); |
105 request.inputStream.onData = () {}; | 105 request.inputStream.onData = () {}; |
106 request.inputStream.onClosed = () { | 106 request.inputStream.onClosed = () { |
107 response.writeString("01234567890"); | 107 response.outputStream.writeString("01234567890"); |
108 response.outputStream.close(); | 108 response.outputStream.close(); |
109 }; | 109 }; |
110 } | 110 } |
111 | 111 |
112 // Return a 404. | 112 // Return a 404. |
113 void _notFoundHandler(HttpRequest request, HttpResponse response) { | 113 void _notFoundHandler(HttpRequest request, HttpResponse response) { |
114 response.statusCode = HttpStatus.NOT_FOUND; | 114 response.statusCode = HttpStatus.NOT_FOUND; |
115 response.setHeader("Content-Type", "text/html; charset=UTF-8"); | 115 response.setHeader("Content-Type", "text/html; charset=UTF-8"); |
116 response.writeString("Page not found"); | 116 response.outputStream.writeString("Page not found"); |
117 response.outputStream.close(); | 117 response.outputStream.close(); |
118 } | 118 } |
119 | 119 |
120 // Return a 301 with a custom reason phrase. | 120 // Return a 301 with a custom reason phrase. |
121 void _reasonForMovingHandler(HttpRequest request, HttpResponse response) { | 121 void _reasonForMovingHandler(HttpRequest request, HttpResponse response) { |
122 response.statusCode = HttpStatus.MOVED_PERMANENTLY; | 122 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
123 response.reasonPhrase = "Don't come looking here any more"; | 123 response.reasonPhrase = "Don't come looking here any more"; |
124 response.outputStream.close(); | 124 response.outputStream.close(); |
125 } | 125 } |
126 | 126 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 TestServerMain testServerMain = new TestServerMain(); | 253 TestServerMain testServerMain = new TestServerMain(); |
254 | 254 |
255 void runTest(int port) { | 255 void runTest(int port) { |
256 int count = 0; | 256 int count = 0; |
257 HttpClient httpClient = new HttpClient(); | 257 HttpClient httpClient = new HttpClient(); |
258 void sendRequest() { | 258 void sendRequest() { |
259 HttpClientConnection conn = | 259 HttpClientConnection conn = |
260 httpClient.post("127.0.0.1", port, "/echo"); | 260 httpClient.post("127.0.0.1", port, "/echo"); |
261 conn.onRequest = (HttpClientRequest request) { | 261 conn.onRequest = (HttpClientRequest request) { |
262 if (chunkedEncoding) { | 262 if (chunkedEncoding) { |
263 request.writeString(data.substring(0, 10)); | 263 request.outputStream.writeString(data.substring(0, 10)); |
264 request.writeString(data.substring(10, data.length)); | 264 request.outputStream.writeString(data.substring(10, data.length)); |
265 } else { | 265 } else { |
266 request.contentLength = data.length; | 266 request.contentLength = data.length; |
267 request.outputStream.write(data.charCodes()); | 267 request.outputStream.write(data.charCodes()); |
268 } | 268 } |
269 request.outputStream.close(); | 269 request.outputStream.close(); |
270 }; | 270 }; |
271 conn.onResponse = (HttpClientResponse response) { | 271 conn.onResponse = (HttpClientResponse response) { |
272 Expect.equals(HttpStatus.OK, response.statusCode); | 272 Expect.equals(HttpStatus.OK, response.statusCode); |
273 StringInputStream stream = new StringInputStream(response.inputStream); | 273 StringInputStream stream = new StringInputStream(response.inputStream); |
274 StringBuffer body = new StringBuffer(); | 274 StringBuffer body = new StringBuffer(); |
(...skipping 29 matching lines...) Expand all Loading... |
304 TestServerMain testServerMain = new TestServerMain(); | 304 TestServerMain testServerMain = new TestServerMain(); |
305 | 305 |
306 void runTest(int port) { | 306 void runTest(int port) { |
307 int count = 0; | 307 int count = 0; |
308 HttpClient httpClient = new HttpClient(); | 308 HttpClient httpClient = new HttpClient(); |
309 void sendRequest() { | 309 void sendRequest() { |
310 HttpClientConnection conn = | 310 HttpClientConnection conn = |
311 httpClient.post("127.0.0.1", port, "/echo"); | 311 httpClient.post("127.0.0.1", port, "/echo"); |
312 conn.onRequest = (HttpClientRequest request) { | 312 conn.onRequest = (HttpClientRequest request) { |
313 if (chunkedEncoding) { | 313 if (chunkedEncoding) { |
314 request.writeString(data.substring(0, 10)); | 314 request.outputStream.writeString(data.substring(0, 10)); |
315 request.writeString(data.substring(10, data.length)); | 315 request.outputStream.writeString(data.substring(10, data.length)); |
316 } else { | 316 } else { |
317 request.contentLength = data.length; | 317 request.contentLength = data.length; |
318 request.outputStream.write(data.charCodes()); | 318 request.outputStream.write(data.charCodes()); |
319 } | 319 } |
320 request.outputStream.close(); | 320 request.outputStream.close(); |
321 }; | 321 }; |
322 conn.onResponse = (HttpClientResponse response) { | 322 conn.onResponse = (HttpClientResponse response) { |
323 Expect.equals(HttpStatus.OK, response.statusCode); | 323 Expect.equals(HttpStatus.OK, response.statusCode); |
324 InputStream stream = response.inputStream; | 324 InputStream stream = response.inputStream; |
325 List<int> body = new List<int>(); | 325 List<int> body = new List<int>(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 TestServerMain testServerMain = new TestServerMain(); | 359 TestServerMain testServerMain = new TestServerMain(); |
360 | 360 |
361 void runTest(int port) { | 361 void runTest(int port) { |
362 int count = 0; | 362 int count = 0; |
363 HttpClient httpClient = new HttpClient(); | 363 HttpClient httpClient = new HttpClient(); |
364 void sendRequest() { | 364 void sendRequest() { |
365 HttpClientConnection conn = | 365 HttpClientConnection conn = |
366 httpClient.post("127.0.0.1", port, "/echo"); | 366 httpClient.post("127.0.0.1", port, "/echo"); |
367 conn.onRequest = (HttpClientRequest request) { | 367 conn.onRequest = (HttpClientRequest request) { |
368 if (chunkedEncoding) { | 368 if (chunkedEncoding) { |
369 request.writeString(data.substring(0, 10)); | 369 request.outputStream.writeString(data.substring(0, 10)); |
370 request.writeString(data.substring(10, data.length)); | 370 request.outputStream.writeString(data.substring(10, data.length)); |
371 } else { | 371 } else { |
372 request.contentLength = data.length; | 372 request.contentLength = data.length; |
373 request.outputStream.write(data.charCodes()); | 373 request.outputStream.write(data.charCodes()); |
374 } | 374 } |
375 request.outputStream.close(); | 375 request.outputStream.close(); |
376 }; | 376 }; |
377 conn.onResponse = (HttpClientResponse response) { | 377 conn.onResponse = (HttpClientResponse response) { |
378 Expect.equals(HttpStatus.OK, response.statusCode); | 378 Expect.equals(HttpStatus.OK, response.statusCode); |
379 InputStream stream = response.inputStream; | 379 InputStream stream = response.inputStream; |
380 List<int> body = new List<int>(); | 380 List<int> body = new List<int>(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 testPOST(false); | 514 testPOST(false); |
515 testReadInto(true); | 515 testReadInto(true); |
516 testReadInto(false); | 516 testReadInto(false); |
517 testReadShort(true); | 517 testReadShort(true); |
518 testReadShort(false); | 518 testReadShort(false); |
519 test404(); | 519 test404(); |
520 testReasonPhrase(); | 520 testReasonPhrase(); |
521 testHost(); | 521 testHost(); |
522 testExpires(); | 522 testExpires(); |
523 } | 523 } |
OLD | NEW |