| 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 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
| 7 // The --short_socket_write option does not work with external server | 7 // VMOptions=--short_socket_write |
| 8 // www.google.dk. Add this to the test when we have secure server sockets. | 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 // See TODO below. | |
| 10 | 9 |
| 11 import "dart:isolate"; | 10 import "dart:isolate"; |
| 12 import "dart:io"; | 11 import "dart:io"; |
| 13 | 12 |
| 14 void WriteAndClose(Socket socket, String message) { | |
| 15 var data = message.charCodes; | |
| 16 int written = 0; | |
| 17 void write() { | |
| 18 written += socket.writeList(data, written, data.length - written); | |
| 19 if (written < data.length) { | |
| 20 socket.onWrite = write; | |
| 21 } else { | |
| 22 socket.close(true); | |
| 23 } | |
| 24 } | |
| 25 write(); | |
| 26 } | |
| 27 | |
| 28 void main() { | 13 void main() { |
| 29 ReceivePort keepAlive = new ReceivePort(); | 14 ReceivePort keepAlive = new ReceivePort(); |
| 30 SecureSocket.initialize(); | 15 SecureSocket.initialize(); |
| 31 // TODO(3593): Use a Dart HTTPS server for this test. | |
| 32 // When we use a Dart HTTPS server, allow --short_socket_write. The flag | |
| 33 // causes fragmentation of the client hello message, which doesn't seem to | |
| 34 // work with www.google.dk. | |
| 35 var secure = new SecureSocket("www.google.dk", 443); | |
| 36 List<String> chunks = <String>[]; | 16 List<String> chunks = <String>[]; |
| 37 secure.onConnect = () { | 17 SecureSocket.connect("www.google.dk", 443).then((socket) { |
| 38 WriteAndClose(secure, "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n"); | 18 socket.add("GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes); |
| 39 }; | 19 socket.close(); |
| 40 var useReadList; // Mutually recursive onData callbacks. | 20 socket.listen( |
| 41 void useRead() { | 21 (List<int> data) { |
| 42 var data = secure.read(); | 22 var received = new String.fromCharCodes(data); |
| 43 var received = new String.fromCharCodes(data); | 23 chunks.add(received); |
| 44 chunks.add(received); | 24 }, |
| 45 secure.onData = useReadList; | 25 onDone: () { |
| 46 } | 26 String fullPage = chunks.join(); |
| 47 useReadList = () { | 27 Expect.isTrue(fullPage.contains('</body></html>')); |
| 48 var buffer = new List.fixedLength(2000); | 28 keepAlive.close(); |
| 49 int len = secure.readList(buffer, 0, 2000); | 29 }, |
| 50 var received = new String.fromCharCodes(buffer.getRange(0, len)); | 30 onError: (e) => Expect.fail("Unexpected error $e")); |
| 51 chunks.add(received); | 31 }); |
| 52 secure.onData = useRead; | |
| 53 }; | |
| 54 secure.onData = useRead; | |
| 55 secure.onClosed = () { | |
| 56 String fullPage = chunks.join(); | |
| 57 Expect.isTrue(fullPage.contains('</body></html>')); | |
| 58 keepAlive.close(); | |
| 59 }; | |
| 60 } | 32 } |
| OLD | NEW |