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:async"; | 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) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 void testStreamResponse() { | 45 void testStreamResponse() { |
46 Timer timer; | 46 Timer timer; |
47 var server = new HttpServer(); | 47 var server = new HttpServer(); |
48 server.onError = (e) { | 48 server.onError = (e) { |
49 server.close(); | 49 server.close(); |
50 timer.cancel(); | 50 timer.cancel(); |
51 }; | 51 }; |
52 server.listen("127.0.0.1", 0, backlog: 5); | 52 server.listen("127.0.0.1", 0, backlog: 5); |
53 server.defaultRequestHandler = (var request, var response) { | 53 server.defaultRequestHandler = (var request, var response) { |
54 timer = new Timer.repeating(10, (_) { | 54 timer = new Timer.repeating(new Duration(milliseconds: 10), (_) { |
55 DateTime now = new DateTime.now(); | 55 DateTime now = new DateTime.now(); |
56 try { | 56 try { |
57 response.outputStream.writeString( | 57 response.outputStream.writeString( |
58 'data:${now.millisecondsSinceEpoch}\n\n'); | 58 'data:${now.millisecondsSinceEpoch}\n\n'); |
59 } catch (e) { | 59 } catch (e) { |
60 timer.cancel(); | 60 timer.cancel(); |
61 server.close(); | 61 server.close(); |
62 } | 62 } |
63 }); | 63 }); |
64 }; | 64 }; |
(...skipping 13 matching lines...) Expand all Loading... |
78 connection.onError = (e) => Expect.isTrue(e is HttpException); | 78 connection.onError = (e) => Expect.isTrue(e is HttpException); |
79 } | 79 } |
80 | 80 |
81 main() { | 81 main() { |
82 testHttp10Close(false); | 82 testHttp10Close(false); |
83 testHttp10Close(true); | 83 testHttp10Close(true); |
84 testHttp11Close(false); | 84 testHttp11Close(false); |
85 testHttp11Close(true); | 85 testHttp11Close(true); |
86 testStreamResponse(); | 86 testStreamResponse(); |
87 } | 87 } |
OLD | NEW |