| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 Expect.equals("POST", request.method); | 104 Expect.equals("POST", request.method); |
| 105 response.contentLength = request.contentLength; | 105 response.contentLength = request.contentLength; |
| 106 request.pipe(response); | 106 request.pipe(response); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Return a 404. | 109 // Return a 404. |
| 110 void _notFoundHandler(HttpRequest request) { | 110 void _notFoundHandler(HttpRequest request) { |
| 111 var response = request.response; | 111 var response = request.response; |
| 112 response.statusCode = HttpStatus.NOT_FOUND; | 112 response.statusCode = HttpStatus.NOT_FOUND; |
| 113 response.headers.set("Content-Type", "text/html; charset=UTF-8"); | 113 response.headers.set("Content-Type", "text/html; charset=UTF-8"); |
| 114 response.addString("Page not found"); | 114 response.write("Page not found"); |
| 115 response.close(); | 115 response.close(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 | 118 |
| 119 void init() { | 119 void init() { |
| 120 // Setup request handlers. | 120 // Setup request handlers. |
| 121 _requestHandlers = new Map(); | 121 _requestHandlers = new Map(); |
| 122 _requestHandlers["/echo"] = _echoHandler; | 122 _requestHandlers["/echo"] = _echoHandler; |
| 123 } | 123 } |
| 124 | 124 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 IsolatedHttpServer server = new IsolatedHttpServer(); | 164 IsolatedHttpServer server = new IsolatedHttpServer(); |
| 165 | 165 |
| 166 void runTest(int port) { | 166 void runTest(int port) { |
| 167 int count = 0; | 167 int count = 0; |
| 168 HttpClient httpClient = new HttpClient(); | 168 HttpClient httpClient = new HttpClient(); |
| 169 void sendRequest() { | 169 void sendRequest() { |
| 170 httpClient.post("127.0.0.1", port, "/echo") | 170 httpClient.post("127.0.0.1", port, "/echo") |
| 171 .then((request) { | 171 .then((request) { |
| 172 if (chunkedEncoding) { | 172 if (chunkedEncoding) { |
| 173 request.addString(data.substring(0, 10)); | 173 request.write(data.substring(0, 10)); |
| 174 request.addString(data.substring(10, data.length)); | 174 request.write(data.substring(10, data.length)); |
| 175 } else { | 175 } else { |
| 176 request.contentLength = data.length; | 176 request.contentLength = data.length; |
| 177 request.add(data.codeUnits); | 177 request.writeBytes(data.codeUnits); |
| 178 } | 178 } |
| 179 return request.close(); | 179 return request.close(); |
| 180 }) | 180 }) |
| 181 .then((response) { | 181 .then((response) { |
| 182 Expect.equals(HttpStatus.OK, response.statusCode); | 182 Expect.equals(HttpStatus.OK, response.statusCode); |
| 183 List<int> body = new List<int>(); | 183 List<int> body = new List<int>(); |
| 184 response.listen( | 184 response.listen( |
| 185 body.addAll, | 185 body.addAll, |
| 186 onDone: () { | 186 onDone: () { |
| 187 Expect.equals(data, new String.fromCharCodes(body)); | 187 Expect.equals(data, new String.fromCharCodes(body)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 if (chunkedEncoding) { | 202 if (chunkedEncoding) { |
| 203 server.chunkedEncoding(); | 203 server.chunkedEncoding(); |
| 204 } | 204 } |
| 205 server.start(); | 205 server.start(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void main() { | 208 void main() { |
| 209 testRead(true); | 209 testRead(true); |
| 210 testRead(false); | 210 testRead(false); |
| 211 } | 211 } |
| OLD | NEW |