| 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 // The --short_socket_write option does not work with external server |
| 8 // www.google.dk. Add this to the test when we have secure server sockets. | 8 // www.google.dk. Add this to the test when we have secure server sockets. |
| 9 // See TODO below. | 9 // See TODO below. |
| 10 | 10 |
| 11 #import("dart:isolate"); | 11 #import("dart:isolate"); |
| 12 #import("dart:io"); | 12 #import("dart:io"); |
| 13 | 13 |
| 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() { | 14 void main() { |
| 29 var testPkcertDatabase = | 15 var testPkcertDatabase = |
| 30 new Path.fromNative(new Options().script).directoryPath.append('pkcert/'); | 16 new Path.fromNative(new Options().script).directoryPath.append('pkcert/'); |
| 31 TlsSocket.setCertificateDatabase(testPkcertDatabase.toNativePath()); | 17 TlsSocket.setCertificateDatabase(testPkcertDatabase.toNativePath()); |
| 32 // TODO(3593): Use a Dart HTTPS server for this test using TLS server sockets. | 18 // TODO(3593): Use a Dart HTTPS server for this test using TLS server sockets. |
| 33 // When we use a Dart HTTPS server, allow --short_socket_write. The flag | 19 // When we use a Dart HTTPS server, allow --short_socket_write. The flag |
| 34 // causes fragmentation of the client hello message, which doesn't seem to | 20 // causes fragmentation of the client hello message, which doesn't seem to |
| 35 // work with www.google.dk. | 21 // work with www.google.dk. |
| 36 var tls = new TlsSocket("www.google.dk", 443); | 22 var tls = new TlsSocket("www.google.dk", 443); |
| 37 List<String> chunks = <String>[]; | 23 List<String> chunks = <String>[]; |
| 38 tls.onConnect = () { | 24 var input = tls.inputStream; |
| 39 WriteAndClose(tls, "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n"); | 25 var output = tls.outputStream; |
| 26 |
| 27 output.write("GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes); |
| 28 output.close(); |
| 29 input.onData = () { |
| 30 chunks.add(new String.fromCharCodes(input.read())); |
| 40 }; | 31 }; |
| 41 var useReadList; // Mutually recursive onData callbacks. | 32 input.onClosed = () { |
| 42 void useRead() { | |
| 43 var data = tls.read(); | |
| 44 var received = new String.fromCharCodes(data); | |
| 45 chunks.add(received); | |
| 46 tls.onData = useReadList; | |
| 47 } | |
| 48 useReadList = () { | |
| 49 var buffer = new List(2000); | |
| 50 int len = tls.readList(buffer, 0, 2000); | |
| 51 var received = new String.fromCharCodes(buffer.getRange(0, len)); | |
| 52 chunks.add(received); | |
| 53 tls.onData = useRead; | |
| 54 }; | |
| 55 tls.onData = useRead; | |
| 56 tls.onClosed = () { | |
| 57 String fullPage = Strings.concatAll(chunks); | 33 String fullPage = Strings.concatAll(chunks); |
| 58 Expect.isTrue(fullPage.contains('</body></html>')); | 34 Expect.isTrue(fullPage.contains('</body></html>')); |
| 59 }; | 35 }; |
| 60 } | 36 } |
| OLD | NEW |