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 "dart:async"; | 10 import "dart:async"; |
11 import "dart:io"; | 11 import "dart:io"; |
12 | 12 |
13 Future<HttpServer> startServer() { | 13 Future<HttpServer> startServer() { |
14 return HttpServer.bindSecure( | 14 return HttpServer.bindSecure( |
15 "127.0.0.1", | 15 "127.0.0.1", |
16 0, | 16 0, |
17 backlog: 5, | 17 backlog: 5, |
18 certificateName: 'localhost_cert').then((server) { | 18 certificateName: 'localhost_cert').then((server) { |
19 server.listen((HttpRequest request) { | 19 server.listen((HttpRequest request) { |
20 request.listen( | 20 request.listen( |
21 (_) { }, | 21 (_) { }, |
22 onDone: () { | 22 onDone: () { |
23 request.response.contentLength = 100; | 23 request.response.contentLength = 100; |
24 for (int i = 0; i < 10; i++) { | 24 for (int i = 0; i < 10; i++) { |
25 request.response.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | 25 request.response.writeBytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); |
26 } | 26 } |
27 request.response.close(); | 27 request.response.close(); |
28 }); | 28 }); |
29 }); | 29 }); |
30 return server; | 30 return server; |
31 }); | 31 }); |
32 } | 32 } |
33 | 33 |
34 void InitializeSSL() { | 34 void InitializeSSL() { |
35 var testPkcertDatabase = | 35 var testPkcertDatabase = |
36 new Path(new Options().script).directoryPath.append('pkcert/'); | 36 new Path(new Options().script).directoryPath.append('pkcert/'); |
37 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), | 37 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), |
38 password: 'dartdart'); | 38 password: 'dartdart'); |
39 } | 39 } |
40 | 40 |
41 void main() { | 41 void main() { |
42 InitializeSSL(); | 42 InitializeSSL(); |
43 List<int> body = <int>[]; | 43 List<int> body = <int>[]; |
44 startServer().then((server) { | 44 startServer().then((server) { |
45 SecureSocket.connect("localhost", server.port).then((socket) { | 45 SecureSocket.connect("localhost", server.port).then((socket) { |
46 socket.add("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n".codeUnits); | 46 socket.write("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n"); |
47 socket.close(); | 47 socket.close(); |
48 socket.listen( | 48 socket.listen( |
49 (List<int> data) { | 49 (List<int> data) { |
50 body.addAll(data); | 50 body.addAll(data); |
51 }, | 51 }, |
52 onDone: () { | 52 onDone: () { |
53 Expect.isTrue(body.length > 100, "$body\n${body.length}"); | 53 Expect.isTrue(body.length > 100, "$body\n${body.length}"); |
54 Expect.equals(72, body[0]); | 54 Expect.equals(72, body[0]); |
55 Expect.equals(9, body[body.length - 1]); | 55 Expect.equals(9, body[body.length - 1]); |
56 server.close(); | 56 server.close(); |
57 }, | 57 }, |
58 onError: (e) => Expect.fail("Unexpected error $e")); | 58 onError: (e) => Expect.fail("Unexpected error $e")); |
59 }); | 59 }); |
60 }); | 60 }); |
61 } | 61 } |
OLD | NEW |