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 30 matching lines...) Expand all Loading... |
41 "content-length: 0\r\n" | 41 "content-length: 0\r\n" |
42 "\r\n" | 42 "\r\n" |
43 "Test!", | 43 "Test!", |
44 body.toString()); | 44 body.toString()); |
45 socket.close(); | 45 socket.close(); |
46 }); | 46 }); |
47 }); | 47 }); |
48 }); | 48 }); |
49 } | 49 } |
50 | 50 |
| 51 void testServerDetachSocketNoWriteHeaders() { |
| 52 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 53 server.listen((request) { |
| 54 var response = request.response; |
| 55 response.contentLength = 0; |
| 56 response.detachSocket(writeHeaders: false).then((socket) { |
| 57 Expect.isNotNull(socket); |
| 58 var body = new StringBuffer(); |
| 59 socket.listen( |
| 60 (data) => body.write(new String.fromCharCodes(data)), |
| 61 onDone: () => Expect.equals("Some data", body.toString())); |
| 62 socket.write("Test!"); |
| 63 socket.close(); |
| 64 }); |
| 65 server.close(); |
| 66 }); |
| 67 |
| 68 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 69 socket.write("GET / HTTP/1.1\r\n" |
| 70 "content-length: 0\r\n\r\n" |
| 71 "Some data"); |
| 72 var body = new StringBuffer(); |
| 73 socket.listen( |
| 74 (data) => body.write(new String.fromCharCodes(data)), |
| 75 onDone: () { |
| 76 Expect.equals("Test!",body.toString()); |
| 77 socket.close(); |
| 78 }); |
| 79 }); |
| 80 }); |
| 81 } |
| 82 |
51 void testBadServerDetachSocket() { | 83 void testBadServerDetachSocket() { |
52 HttpServer.bind("127.0.0.1", 0).then((server) { | 84 HttpServer.bind("127.0.0.1", 0).then((server) { |
53 server.listen((request) { | 85 server.listen((request) { |
54 var response = request.response; | 86 var response = request.response; |
55 response.contentLength = 0; | 87 response.contentLength = 0; |
56 response.close(); | 88 response.close(); |
57 Expect.throws(response.detachSocket); | 89 Expect.throws(response.detachSocket); |
58 server.close(); | 90 server.close(); |
59 }); | 91 }); |
60 | 92 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 }); | 140 }); |
109 socket.write("Some data"); | 141 socket.write("Some data"); |
110 socket.close(); | 142 socket.close(); |
111 }); | 143 }); |
112 }); | 144 }); |
113 }); | 145 }); |
114 } | 146 } |
115 | 147 |
116 void main() { | 148 void main() { |
117 testServerDetachSocket(); | 149 testServerDetachSocket(); |
| 150 testServerDetachSocketNoWriteHeaders(); |
118 testBadServerDetachSocket(); | 151 testBadServerDetachSocket(); |
119 testClientDetachSocket(); | 152 testClientDetachSocket(); |
120 } | 153 } |
OLD | NEW |