| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 Expect.equals("POST", request.method); | 103 Expect.equals("POST", request.method); |
| 104 response.contentLength = request.contentLength; | 104 response.contentLength = request.contentLength; |
| 105 request.pipe(response); | 105 request.pipe(response); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Echo the request content back to the response. | 108 // Echo the request content back to the response. |
| 109 void _zeroToTenHandler(HttpRequest request) { | 109 void _zeroToTenHandler(HttpRequest request) { |
| 110 var response = request.response; | 110 var response = request.response; |
| 111 Expect.equals("GET", request.method); | 111 Expect.equals("GET", request.method); |
| 112 request.listen((_) {}, onDone: () { | 112 request.listen((_) {}, onDone: () { |
| 113 response.addString("01234567890"); | 113 response.write("01234567890"); |
| 114 response.close(); | 114 response.close(); |
| 115 }); | 115 }); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Return a 404. | 118 // Return a 404. |
| 119 void _notFoundHandler(HttpRequest request) { | 119 void _notFoundHandler(HttpRequest request) { |
| 120 var response = request.response; | 120 var response = request.response; |
| 121 response.statusCode = HttpStatus.NOT_FOUND; | 121 response.statusCode = HttpStatus.NOT_FOUND; |
| 122 response.headers.set("Content-Type", "text/html; charset=UTF-8"); | 122 response.headers.set("Content-Type", "text/html; charset=UTF-8"); |
| 123 response.addString("Page not found"); | 123 response.write("Page not found"); |
| 124 response.close(); | 124 response.close(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Return a 301 with a custom reason phrase. | 127 // Return a 301 with a custom reason phrase. |
| 128 void _reasonForMovingHandler(HttpRequest request) { | 128 void _reasonForMovingHandler(HttpRequest request) { |
| 129 var response = request.response; | 129 var response = request.response; |
| 130 response.statusCode = HttpStatus.MOVED_PERMANENTLY; | 130 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 131 response.reasonPhrase = "Don't come looking here any more"; | 131 response.reasonPhrase = "Don't come looking here any more"; |
| 132 response.close(); | 132 response.close(); |
| 133 } | 133 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 TestServerMain testServerMain = new TestServerMain(); | 222 TestServerMain testServerMain = new TestServerMain(); |
| 223 | 223 |
| 224 void runTest(int port) { | 224 void runTest(int port) { |
| 225 int count = 0; | 225 int count = 0; |
| 226 HttpClient httpClient = new HttpClient(); | 226 HttpClient httpClient = new HttpClient(); |
| 227 void sendRequest() { | 227 void sendRequest() { |
| 228 httpClient.post("127.0.0.1", port, "/echo") | 228 httpClient.post("127.0.0.1", port, "/echo") |
| 229 .then((request) { | 229 .then((request) { |
| 230 if (chunkedEncoding) { | 230 if (chunkedEncoding) { |
| 231 request.addString(data.substring(0, 10)); | 231 request.write(data.substring(0, 10)); |
| 232 request.addString(data.substring(10, data.length)); | 232 request.write(data.substring(10, data.length)); |
| 233 } else { | 233 } else { |
| 234 request.contentLength = data.length; | 234 request.contentLength = data.length; |
| 235 request.addString(data); | 235 request.write(data); |
| 236 } | 236 } |
| 237 return request.close(); | 237 return request.close(); |
| 238 }) | 238 }) |
| 239 .then((response) { | 239 .then((response) { |
| 240 Expect.equals(HttpStatus.OK, response.statusCode); | 240 Expect.equals(HttpStatus.OK, response.statusCode); |
| 241 StringBuffer body = new StringBuffer(); | 241 StringBuffer body = new StringBuffer(); |
| 242 response.listen( | 242 response.listen( |
| 243 (data) => body.add(new String.fromCharCodes(data)), | 243 (data) => body.add(new String.fromCharCodes(data)), |
| 244 onDone: () { | 244 onDone: () { |
| 245 Expect.equals(data, body.toString()); | 245 Expect.equals(data, body.toString()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 | 311 |
| 312 void main() { | 312 void main() { |
| 313 testStartStop(); | 313 testStartStop(); |
| 314 testGET(); | 314 testGET(); |
| 315 testPOST(true); | 315 testPOST(true); |
| 316 testPOST(false); | 316 testPOST(false); |
| 317 test404(); | 317 test404(); |
| 318 testReasonPhrase(); | 318 testReasonPhrase(); |
| 319 } | 319 } |
| OLD | NEW |