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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 socket.listen((_) {}, onDone: () { | 98 socket.listen((_) {}, onDone: () { |
99 socket.close(); | 99 socket.close(); |
100 }); | 100 }); |
101 }); | 101 }); |
102 }); | 102 }); |
103 } | 103 } |
104 | 104 |
105 void testClientDetachSocket() { | 105 void testClientDetachSocket() { |
106 ServerSocket.bind("127.0.0.1", 0).then((server) { | 106 ServerSocket.bind("127.0.0.1", 0).then((server) { |
107 server.listen((socket) { | 107 server.listen((socket) { |
| 108 int port = server.port; |
108 socket.write("HTTP/1.1 200 OK\r\n" | 109 socket.write("HTTP/1.1 200 OK\r\n" |
109 "\r\n" | 110 "\r\n" |
110 "Test!"); | 111 "Test!"); |
111 var body = new StringBuffer(); | 112 var body = new StringBuffer(); |
112 socket.listen( | 113 socket.listen( |
113 (data) => body.write(new String.fromCharCodes(data)), | 114 (data) => body.write(new String.fromCharCodes(data)), |
114 onDone: () { | 115 onDone: () { |
115 List<String> lines = body.toString().split("\r\n"); | 116 List<String> lines = body.toString().split("\r\n"); |
116 Expect.equals(6, lines.length); | 117 Expect.equals(6, lines.length); |
117 Expect.equals("GET / HTTP/1.1", lines[0]); | 118 Expect.equals("GET / HTTP/1.1", lines[0]); |
118 Expect.equals("", lines[4]); | 119 Expect.equals("", lines[4]); |
119 Expect.equals("Some data", lines[5]); | 120 Expect.equals("Some data", lines[5]); |
120 lines.sort(); // Lines 1-3 becomes 3-5 in a fixed order. | 121 lines.sort(); // Lines 1-3 becomes 3-5 in a fixed order. |
121 Expect.equals("accept-encoding: gzip", lines[3]); | 122 Expect.equals("accept-encoding: gzip", lines[3]); |
122 Expect.equals("content-length: 0", lines[4]); | 123 Expect.equals("content-length: 0", lines[4]); |
123 Expect.equals("host: 127.0.0.1:${server.port}", lines[5]); | 124 Expect.equals("host: 127.0.0.1:${port}", lines[5]); |
124 socket.close(); | 125 socket.close(); |
125 }); | 126 }); |
126 server.close(); | 127 server.close(); |
127 }); | 128 }); |
128 | 129 |
129 var client = new HttpClient(); | 130 var client = new HttpClient(); |
130 client.userAgent = null; | 131 client.userAgent = null; |
131 client.get("127.0.0.1", server.port, "/") | 132 client.get("127.0.0.1", server.port, "/") |
132 .then((request) => request.close()) | 133 .then((request) => request.close()) |
133 .then((response) { | 134 .then((response) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 }); | 198 }); |
198 } | 199 } |
199 | 200 |
200 void main() { | 201 void main() { |
201 testServerDetachSocket(); | 202 testServerDetachSocket(); |
202 testServerDetachSocketNoWriteHeaders(); | 203 testServerDetachSocketNoWriteHeaders(); |
203 testBadServerDetachSocket(); | 204 testBadServerDetachSocket(); |
204 testClientDetachSocket(); | 205 testClientDetachSocket(); |
205 testUpgradedConnection(); | 206 testUpgradedConnection(); |
206 } | 207 } |
OLD | NEW |