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:async'; | 10 import 'dart:async'; |
(...skipping 14 matching lines...) Expand all Loading... |
25 (data) {}, | 25 (data) {}, |
26 onDone: server.close); | 26 onDone: server.close); |
27 }); | 27 }); |
28 }); | 28 }); |
29 } | 29 } |
30 | 30 |
31 void testGetDataRequest() { | 31 void testGetDataRequest() { |
32 HttpServer.bind().then((server) { | 32 HttpServer.bind().then((server) { |
33 var data = "lalala".codeUnits; | 33 var data = "lalala".codeUnits; |
34 server.listen((request) { | 34 server.listen((request) { |
35 request.response.add(data); | 35 request.response.writeBytes(data); |
36 request.pipe(request.response); | 36 request.pipe(request.response); |
37 }); | 37 }); |
38 | 38 |
39 var client = new HttpClient(); | 39 var client = new HttpClient(); |
40 client.get("127.0.0.1", server.port, "/") | 40 client.get("127.0.0.1", server.port, "/") |
41 .then((request) => request.close()) | 41 .then((request) => request.close()) |
42 .then((response) { | 42 .then((response) { |
43 int count = 0; | 43 int count = 0; |
44 response.listen( | 44 response.listen( |
45 (data) => count += data.length, | 45 (data) => count += data.length, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 .catchError((error) => port.close(), | 77 .catchError((error) => port.close(), |
78 test: (error) => error is HttpParserException); | 78 test: (error) => error is HttpParserException); |
79 }); | 79 }); |
80 } | 80 } |
81 | 81 |
82 void testGetDataServerClose() { | 82 void testGetDataServerClose() { |
83 var completer = new Completer(); | 83 var completer = new Completer(); |
84 HttpServer.bind().then((server) { | 84 HttpServer.bind().then((server) { |
85 server.listen((request) { | 85 server.listen((request) { |
86 request.response.contentLength = 100; | 86 request.response.contentLength = 100; |
87 request.response.addString("data"); | 87 request.response.write("data"); |
88 request.response.addString("more data"); | 88 request.response.write("more data"); |
89 completer.future.then((_) => server.close()); | 89 completer.future.then((_) => server.close()); |
90 }); | 90 }); |
91 | 91 |
92 var port = new ReceivePort(); | 92 var port = new ReceivePort(); |
93 var client = new HttpClient(); | 93 var client = new HttpClient(); |
94 client.get("127.0.0.1", server.port, "/") | 94 client.get("127.0.0.1", server.port, "/") |
95 .then((request) => request.close()) | 95 .then((request) => request.close()) |
96 .then((response) { | 96 .then((response) { |
97 // Close the (incomplete) response, now we have seen the response object
. | 97 // Close the (incomplete) response, now we have seen the response object
. |
98 completer.complete(null); | 98 completer.complete(null); |
(...skipping 26 matching lines...) Expand all Loading... |
125 | 125 |
126 | 126 |
127 void main() { | 127 void main() { |
128 testGetEmptyRequest(); | 128 testGetEmptyRequest(); |
129 testGetDataRequest(); | 129 testGetDataRequest(); |
130 testGetInvalidHost(); | 130 testGetInvalidHost(); |
131 testGetServerClose(); | 131 testGetServerClose(); |
132 testGetDataServerClose(); | 132 testGetDataServerClose(); |
133 testPostEmptyRequest(); | 133 testPostEmptyRequest(); |
134 } | 134 } |
OLD | NEW |