OLD | NEW |
1 // (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // (c) 2014, 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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
11 import "dart:async"; | 11 import "dart:async"; |
12 import "dart:isolate"; | 12 import "dart:isolate"; |
13 import "dart:io"; | 13 import "dart:io"; |
14 | 14 |
15 // Test that a response line without any reason phrase is handled. | 15 // Test that a response line without any reason phrase is handled. |
16 void missingReasonPhrase(int statusCode, bool includeSpace) { | 16 void missingReasonPhrase(int statusCode, bool includeSpace) { |
17 var client = new HttpClient(); | 17 var client = new HttpClient(); |
18 ServerSocket.bind("127.0.0.1", 0).then((server) { | 18 ServerSocket.bind("127.0.0.1", 0).then((server) { |
19 server.listen((client) { | 19 server.listen((client) { |
| 20 client.listen(null); |
20 if (includeSpace) { | 21 if (includeSpace) { |
21 client.write("HTTP/1.1 $statusCode \r\n\r\n"); | 22 client.write("HTTP/1.1 $statusCode \r\n\r\n"); |
22 } else { | 23 } else { |
23 client.write("HTTP/1.1 $statusCode\r\n\r\n"); | 24 client.write("HTTP/1.1 $statusCode\r\n\r\n"); |
24 } | 25 } |
25 client.close(); | 26 client.close(); |
26 }); | 27 }); |
27 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/")) | 28 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/")) |
28 .then((request) => request.close()) | 29 .then((request) => request.close()) |
29 .then((response) { | 30 .then((response) { |
30 Expect.equals(statusCode, response.statusCode); | 31 Expect.equals(statusCode, response.statusCode); |
31 Expect.equals("", response.reasonPhrase); | 32 Expect.equals("", response.reasonPhrase); |
| 33 return response.drain(); |
32 }) | 34 }) |
33 .whenComplete(() => server.close()); | 35 .whenComplete(() => server.close()); |
34 }); | 36 }); |
35 } | 37 } |
36 | 38 |
37 void main() { | 39 void main() { |
38 missingReasonPhrase(HttpStatus.OK, true); | 40 missingReasonPhrase(HttpStatus.OK, true); |
39 missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, true); | 41 missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, true); |
40 missingReasonPhrase(HttpStatus.OK, false); | 42 missingReasonPhrase(HttpStatus.OK, false); |
41 missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, false); | 43 missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, false); |
42 } | 44 } |
OLD | NEW |