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 "dart:io"; | 11 import "dart:io"; |
12 import "dart:isolate"; | 12 import "dart:isolate"; |
13 | 13 |
14 void testServerDetachSocket() { | 14 void testServerDetachSocket() { |
15 HttpServer.bind("127.0.0.1", 0).then((server) { | 15 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 16 server.serverHeader = null; |
16 server.listen((request) { | 17 server.listen((request) { |
17 var response = request.response; | 18 var response = request.response; |
18 response.contentLength = 0; | 19 response.contentLength = 0; |
19 response.detachSocket().then((socket) { | 20 response.detachSocket().then((socket) { |
20 Expect.isNotNull(socket); | 21 Expect.isNotNull(socket); |
21 var body = new StringBuffer(); | 22 var body = new StringBuffer(); |
22 socket.listen( | 23 socket.listen( |
23 (data) => body.write(new String.fromCharCodes(data)), | 24 (data) => body.write(new String.fromCharCodes(data)), |
24 onDone: () => Expect.equals("Some data", body.toString())); | 25 onDone: () => Expect.equals("Some data", body.toString())); |
25 socket.write("Test!"); | 26 socket.write("Test!"); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 "content-length: 0\r\n" | 83 "content-length: 0\r\n" |
83 "host: 127.0.0.1:${server.port}\r\n\r\n" | 84 "host: 127.0.0.1:${server.port}\r\n\r\n" |
84 "Some data", | 85 "Some data", |
85 body.toString()); | 86 body.toString()); |
86 socket.close(); | 87 socket.close(); |
87 }); | 88 }); |
88 server.close(); | 89 server.close(); |
89 }); | 90 }); |
90 | 91 |
91 var client = new HttpClient(); | 92 var client = new HttpClient(); |
| 93 client.userAgent = null; |
92 client.get("127.0.0.1", server.port, "/") | 94 client.get("127.0.0.1", server.port, "/") |
93 .then((request) => request.close()) | 95 .then((request) => request.close()) |
94 .then((response) { | 96 .then((response) { |
95 response.detachSocket().then((socket) { | 97 response.detachSocket().then((socket) { |
96 var body = new StringBuffer(); | 98 var body = new StringBuffer(); |
97 socket.listen( | 99 socket.listen( |
98 (data) => body.write(new String.fromCharCodes(data)), | 100 (data) => body.write(new String.fromCharCodes(data)), |
99 onDone: () { | 101 onDone: () { |
100 Expect.equals("Test!", | 102 Expect.equals("Test!", |
101 body.toString()); | 103 body.toString()); |
102 client.close(); | 104 client.close(); |
103 }); | 105 }); |
104 socket.write("Some data"); | 106 socket.write("Some data"); |
105 socket.close(); | 107 socket.close(); |
106 }); | 108 }); |
107 }); | 109 }); |
108 }); | 110 }); |
109 } | 111 } |
110 | 112 |
111 void main() { | 113 void main() { |
112 testServerDetachSocket(); | 114 testServerDetachSocket(); |
113 testBadServerDetachSocket(); | 115 testBadServerDetachSocket(); |
114 testClientDetachSocket(); | 116 testClientDetachSocket(); |
115 } | 117 } |
OLD | NEW |