| 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 Future<int> getStatusCode(int port, | 11 Future<int> getStatusCode(int port, |
| 12 String path, | 12 String path, |
| 13 {String host, | 13 {String host, |
| 14 bool secure: false, | 14 bool secure: false, |
| 15 DateTime ifModifiedSince, | 15 DateTime ifModifiedSince, |
| 16 bool rawPath: false}) { | 16 bool rawPath: false, |
| 17 bool followRedirects: true}) { |
| 17 Uri uri; | 18 Uri uri; |
| 18 if (rawPath) { | 19 if (rawPath) { |
| 19 uri = new Uri(scheme: secure ? 'https' : 'http', | 20 uri = new Uri(scheme: secure ? 'https' : 'http', |
| 20 host: 'localhost', | 21 host: 'localhost', |
| 21 port: port, | 22 port: port, |
| 22 path: path); | 23 path: path); |
| 23 } else { | 24 } else { |
| 24 uri = (secure ? | 25 uri = (secure ? |
| 25 new Uri.https('localhost:$port', path) : | 26 new Uri.https('localhost:$port', path) : |
| 26 new Uri.http('localhost:$port', path)); | 27 new Uri.http('localhost:$port', path)); |
| 27 } | 28 } |
| 28 | 29 |
| 29 return new HttpClient().getUrl(uri) | 30 return new HttpClient().getUrl(uri) |
| 30 .then((request) { | 31 .then((request) { |
| 32 if (!followRedirects) request.followRedirects = false; |
| 31 if (host != null) request.headers.host = host; | 33 if (host != null) request.headers.host = host; |
| 32 if (ifModifiedSince != null) { | 34 if (ifModifiedSince != null) { |
| 33 request.headers.ifModifiedSince = ifModifiedSince; | 35 request.headers.ifModifiedSince = ifModifiedSince; |
| 34 } | 36 } |
| 35 return request.close(); | 37 return request.close(); |
| 36 }) | 38 }) |
| 37 .then((response) => response.drain().then( | 39 .then((response) => response.drain().then( |
| 38 (_) => response.statusCode)); | 40 (_) => response.statusCode)); |
| 39 } | 41 } |
| 40 | 42 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 | 58 |
| 57 | 59 |
| 58 const CERTIFICATE = "localhost_cert"; | 60 const CERTIFICATE = "localhost_cert"; |
| 59 | 61 |
| 60 | 62 |
| 61 void setupSecure() { | 63 void setupSecure() { |
| 62 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); | 64 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 63 SecureSocket.initialize(database: certificateDatabase, | 65 SecureSocket.initialize(database: certificateDatabase, |
| 64 password: 'dartdart'); | 66 password: 'dartdart'); |
| 65 } | 67 } |
| OLD | NEW |