OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 5 |
6 import "dart:isolate"; | 6 import "dart:async"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:uri"; | 8 import "dart:uri"; |
9 | 9 |
10 void testHttp10Close(bool closeRequest) { | 10 void testHttp10Close(bool closeRequest) { |
11 HttpServer server = new HttpServer(); | 11 HttpServer server = new HttpServer(); |
12 server.listen("127.0.0.1", 0, backlog: 5); | 12 server.listen("127.0.0.1", 0, backlog: 5); |
13 | 13 |
14 Socket socket = new Socket("127.0.0.1", server.port); | 14 Socket socket = new Socket("127.0.0.1", server.port); |
15 socket.onConnect = () { | 15 socket.onConnect = () { |
16 List<int> buffer = new List<int>(1024); | 16 List<int> buffer = new List<int>.fixedLength(1024); |
17 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n"); | 17 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n"); |
18 if (closeRequest) socket.outputStream.close(); | 18 if (closeRequest) socket.outputStream.close(); |
19 socket.onData = () => socket.readList(buffer, 0, buffer.length); | 19 socket.onData = () => socket.readList(buffer, 0, buffer.length); |
20 socket.onClosed = () { | 20 socket.onClosed = () { |
21 if (!closeRequest) socket.close(true); | 21 if (!closeRequest) socket.close(true); |
22 server.close(); | 22 server.close(); |
23 }; | 23 }; |
24 }; | 24 }; |
25 } | 25 } |
26 | 26 |
27 void testHttp11Close(bool closeRequest) { | 27 void testHttp11Close(bool closeRequest) { |
28 HttpServer server = new HttpServer(); | 28 HttpServer server = new HttpServer(); |
29 server.listen("127.0.0.1", 0, backlog: 5); | 29 server.listen("127.0.0.1", 0, backlog: 5); |
30 | 30 |
31 Socket socket = new Socket("127.0.0.1", server.port); | 31 Socket socket = new Socket("127.0.0.1", server.port); |
32 socket.onConnect = () { | 32 socket.onConnect = () { |
33 List<int> buffer = new List<int>(1024); | 33 List<int> buffer = new List<int>.fixedLength(1024); |
34 socket.outputStream.writeString( | 34 socket.outputStream.writeString( |
35 "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"); | 35 "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"); |
36 if (closeRequest) socket.outputStream.close(); | 36 if (closeRequest) socket.outputStream.close(); |
37 socket.onData = () => socket.readList(buffer, 0, buffer.length); | 37 socket.onData = () => socket.readList(buffer, 0, buffer.length); |
38 socket.onClosed = () { | 38 socket.onClosed = () { |
39 if (!closeRequest) socket.close(true); | 39 if (!closeRequest) socket.close(true); |
40 server.close(); | 40 server.close(); |
41 }; | 41 }; |
42 }; | 42 }; |
43 } | 43 } |
(...skipping 29 matching lines...) Expand all Loading... |
73 connection.onError = (e) => Expect.isTrue(e is HttpException); | 73 connection.onError = (e) => Expect.isTrue(e is HttpException); |
74 } | 74 } |
75 | 75 |
76 main() { | 76 main() { |
77 testHttp10Close(false); | 77 testHttp10Close(false); |
78 testHttp10Close(true); | 78 testHttp10Close(true); |
79 testHttp11Close(false); | 79 testHttp11Close(false); |
80 testHttp11Close(true); | 80 testHttp11Close(true); |
81 testStreamResponse(); | 81 testStreamResponse(); |
82 } | 82 } |
OLD | NEW |