| 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:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 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 var uri = (secure ? | 16 bool rawPath: false}) { |
| 17 new Uri.https('localhost:$port', path) : | 17 var uri; |
| 18 new Uri.http('localhost:$port', path)); | 18 if (rawPath) { |
| 19 uri = new Uri(scheme: secure ? 'https' : 'http', |
| 20 host: 'localhost', |
| 21 port: port, |
| 22 path: path); |
| 23 } else { |
| 24 uri = (secure ? |
| 25 new Uri.https('localhost:$port', path) : |
| 26 new Uri.http('localhost:$port', path)); |
| 27 } |
| 19 return new HttpClient().getUrl(uri) | 28 return new HttpClient().getUrl(uri) |
| 20 .then((request) { | 29 .then((request) { |
| 21 if (host != null) request.headers.host = host; | 30 if (host != null) request.headers.host = host; |
| 22 if (ifModifiedSince != null) { | 31 if (ifModifiedSince != null) { |
| 23 request.headers.ifModifiedSince = ifModifiedSince; | 32 request.headers.ifModifiedSince = ifModifiedSince; |
| 24 } | 33 } |
| 25 return request.close(); | 34 return request.close(); |
| 26 }) | 35 }) |
| 27 .then((response) => response.drain().then( | 36 .then((response) => response.drain().then( |
| 28 (_) => response.statusCode)); | 37 (_) => response.statusCode)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 46 | 55 |
| 47 const CERTIFICATE = "localhost_cert"; | 56 const CERTIFICATE = "localhost_cert"; |
| 48 | 57 |
| 49 | 58 |
| 50 setupSecure() { | 59 setupSecure() { |
| 51 Path scriptDir = new Path(new Options().script).directoryPath; | 60 Path scriptDir = new Path(new Options().script).directoryPath; |
| 52 Path certificateDatabase = scriptDir.append('pkcert'); | 61 Path certificateDatabase = scriptDir.append('pkcert'); |
| 53 SecureSocket.initialize(database: certificateDatabase.toNativePath(), | 62 SecureSocket.initialize(database: certificateDatabase.toNativePath(), |
| 54 password: 'dartdart'); | 63 password: 'dartdart'); |
| 55 } | 64 } |
| OLD | NEW |