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"; |
| 11 import "package:async_helper/async_helper.dart"; |
11 import "dart:io"; | 12 import "dart:io"; |
12 import "dart:isolate"; | 13 import "dart:isolate"; |
13 | 14 |
14 void testServerDetachSocket() { | 15 void testServerDetachSocket() { |
15 HttpServer.bind("127.0.0.1", 0).then((server) { | 16 HttpServer.bind("127.0.0.1", 0).then((server) { |
16 server.serverHeader = null; | 17 server.serverHeader = null; |
17 server.listen((request) { | 18 server.listen((request) { |
18 var response = request.response; | 19 var response = request.response; |
19 response.contentLength = 0; | 20 response.contentLength = 0; |
20 response.detachSocket().then((socket) { | 21 response.detachSocket().then((socket) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 body.toString()); | 139 body.toString()); |
139 client.close(); | 140 client.close(); |
140 }); | 141 }); |
141 socket.write("Some data"); | 142 socket.write("Some data"); |
142 socket.close(); | 143 socket.close(); |
143 }); | 144 }); |
144 }); | 145 }); |
145 }); | 146 }); |
146 } | 147 } |
147 | 148 |
| 149 void testUpgradedConnection() { |
| 150 asyncStart(); |
| 151 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 152 server.listen((request) { |
| 153 request.response.headers.set('connection', 'upgrade'); |
| 154 if (request.headers.value('upgrade') == 'mine') { |
| 155 asyncStart(); |
| 156 request.response.detachSocket().then((socket) { |
| 157 socket.pipe(socket).then((_) { |
| 158 asyncEnd(); |
| 159 }); |
| 160 }); |
| 161 } else { |
| 162 request.response.close(); |
| 163 } |
| 164 }); |
| 165 |
| 166 var client = new HttpClient(); |
| 167 client.userAgent = null; |
| 168 client.get("127.0.0.1", server.port, "/") |
| 169 .then((request) { |
| 170 request.headers.set('upgrade', 'mine'); |
| 171 return request.close(); |
| 172 }) |
| 173 .then((response) { |
| 174 client.get("127.0.0.1", server.port, "/") |
| 175 .then((request) { |
| 176 response.detachSocket().then((socket) { |
| 177 // We are testing that we can detach the socket, even though |
| 178 // we made a new connection (testing it was not reused). |
| 179 request.close().then((response) { |
| 180 asyncStart(); |
| 181 response.listen(null, onDone: () { |
| 182 server.close(); |
| 183 asyncEnd(); |
| 184 }); |
| 185 socket.add([0]); |
| 186 socket.close(); |
| 187 socket.fold([], (l, d) => l..addAll(d)) |
| 188 .then((data) { |
| 189 asyncEnd(); |
| 190 Expect.listEquals([0], data); |
| 191 }); |
| 192 }); |
| 193 }); |
| 194 }); |
| 195 }); |
| 196 }); |
| 197 } |
| 198 |
148 void main() { | 199 void main() { |
149 testServerDetachSocket(); | 200 testServerDetachSocket(); |
150 testServerDetachSocketNoWriteHeaders(); | 201 testServerDetachSocketNoWriteHeaders(); |
151 testBadServerDetachSocket(); | 202 testBadServerDetachSocket(); |
152 testClientDetachSocket(); | 203 testClientDetachSocket(); |
| 204 testUpgradedConnection(); |
153 } | 205 } |
OLD | NEW |