Chromium Code Reviews| 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 #import("dart:io"); | 5 #import("dart:io"); |
| 6 #import("dart:uri"); | 6 #import("dart:uri"); |
| 7 #import("dart:isolate"); | 7 #import("dart:isolate"); |
| 8 | 8 |
| 9 void testGoogle() { | 9 void testGoogle() { |
| 10 HttpClient client = new HttpClient(); | 10 HttpClient client = new HttpClient(); |
| 11 var conn = client.get('www.google.com', 80, '/'); | 11 var conn = client.get('www.google.com', 80, '/'); |
| 12 | 12 |
| 13 conn.onRequest = (HttpClientRequest request) { | 13 conn.onRequest = (HttpClientRequest request) { |
| 14 request.keepAlive = false; | |
|
Anders Johnsen
2012/04/13 09:02:38
Since you have changed keepAlive to be on by defau
Søren Gjesse
2012/04/13 10:58:31
I don't think so. I don't even know why it was her
| |
| 15 request.outputStream.close(); | 14 request.outputStream.close(); |
| 16 }; | 15 }; |
| 17 conn.onResponse = (HttpClientResponse response) { | 16 conn.onResponse = (HttpClientResponse response) { |
| 18 Expect.isTrue(response.statusCode < 500); | 17 Expect.isTrue(response.statusCode < 500); |
| 19 response.inputStream.onData = () { | 18 response.inputStream.onData = () { |
| 20 response.inputStream.read(); | 19 response.inputStream.read(); |
| 21 }; | 20 }; |
| 22 response.inputStream.onClosed = () { | 21 response.inputStream.onClosed = () { |
| 23 client.shutdown(); | 22 client.shutdown(); |
| 24 }; | 23 }; |
| 25 }; | 24 }; |
| 26 conn.onError = (error) => Expect.fail("Unexpected IO error"); | 25 conn.onError = (error) => Expect.fail("Unexpected IO error"); |
| 27 } | 26 } |
| 28 | 27 |
| 29 void testGoogleUrl() { | 28 void testGoogleUrl() { |
| 30 HttpClient client = new HttpClient(); | 29 HttpClient client = new HttpClient(); |
| 31 | 30 |
| 32 void testUrl(String url) { | 31 void testUrl(String url) { |
| 33 var conn = client.getUrl(new Uri.fromString(url)); | 32 var conn = client.getUrl(new Uri.fromString(url)); |
| 34 | 33 |
| 35 conn.onRequest = (HttpClientRequest request) { | 34 conn.onRequest = (HttpClientRequest request) { |
| 36 request.keepAlive = false; | |
| 37 request.outputStream.close(); | 35 request.outputStream.close(); |
| 38 }; | 36 }; |
| 39 conn.onResponse = (HttpClientResponse response) { | 37 conn.onResponse = (HttpClientResponse response) { |
| 40 Expect.isTrue(response.statusCode < 500); | 38 Expect.isTrue(response.statusCode < 500); |
| 41 response.inputStream.onData = () { | 39 response.inputStream.onData = () { |
| 42 response.inputStream.read(); | 40 response.inputStream.read(); |
| 43 }; | 41 }; |
| 44 response.inputStream.onClosed = () { | 42 response.inputStream.onClosed = () { |
| 45 client.shutdown(); | 43 client.shutdown(); |
| 46 }; | 44 }; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 77 } | 75 } |
| 78 | 76 |
| 79 void main() { | 77 void main() { |
| 80 // TODO(sgjesse): Making empty www.google.com requests seems to fail | 78 // TODO(sgjesse): Making empty www.google.com requests seems to fail |
| 81 //on buildbot. | 79 //on buildbot. |
| 82 //testGoogle(); | 80 //testGoogle(); |
| 83 //testGoogleUrl(); | 81 //testGoogleUrl(); |
| 84 testInvalidUrl(); | 82 testInvalidUrl(); |
| 85 testBadHostName(); | 83 testBadHostName(); |
| 86 } | 84 } |
| OLD | NEW |