| 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 import "package:unittest/unittest.dart"; | 10 import "package:unittest/unittest.dart"; |
| 11 | 11 |
| 12 import 'package:http_server/http_server.dart'; | 12 import 'package:http_server/http_server.dart'; |
| 13 | 13 |
| 14 import 'http_mock.dart'; | 14 import 'http_mock.dart'; |
| 15 | 15 |
| 16 SecurityContext serverContext; |
| 17 SecurityContext clientContext; |
| 18 |
| 16 /** | 19 /** |
| 17 * Used to flag a given test case as being a mock or not. | 20 * Used to flag a given test case as being a mock or not. |
| 18 */ | 21 */ |
| 19 final _isMockTestExpando = new Expando<bool>('isMockTest'); | 22 final _isMockTestExpando = new Expando<bool>('isMockTest'); |
| 20 | 23 |
| 21 void testVirtualDir(String name, Future func(Directory dir)) { | 24 void testVirtualDir(String name, Future func(Directory dir)) { |
| 22 _testVirtualDir(name, false, func); | 25 _testVirtualDir(name, false, func); |
| 23 _testVirtualDir(name, true, func); | 26 _testVirtualDir(name, true, func); |
| 24 } | 27 } |
| 25 | 28 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 String path, | 81 String path, |
| 79 {String host, | 82 {String host, |
| 80 bool secure: false, | 83 bool secure: false, |
| 81 DateTime ifModifiedSince, | 84 DateTime ifModifiedSince, |
| 82 bool rawPath: false, | 85 bool rawPath: false, |
| 83 bool followRedirects: true, | 86 bool followRedirects: true, |
| 84 int from, | 87 int from, |
| 85 int to}) { | 88 int to}) { |
| 86 var uri = _getUri(port, path, secure: secure, rawPath: rawPath); | 89 var uri = _getUri(port, path, secure: secure, rawPath: rawPath); |
| 87 | 90 |
| 88 var client = new HttpClient(); | 91 var client; |
| 92 if (secure) { |
| 93 client = new HttpClient(context: clientContext); |
| 94 } else { |
| 95 client = new HttpClient(); |
| 96 } |
| 89 return client.getUrl(uri) | 97 return client.getUrl(uri) |
| 90 .then((request) { | 98 .then((request) { |
| 91 if (!followRedirects) request.followRedirects = false; | 99 if (!followRedirects) request.followRedirects = false; |
| 92 if (host != null) request.headers.host = host; | 100 if (host != null) request.headers.host = host; |
| 93 if (ifModifiedSince != null) { | 101 if (ifModifiedSince != null) { |
| 94 request.headers.ifModifiedSince = ifModifiedSince; | 102 request.headers.ifModifiedSince = ifModifiedSince; |
| 95 } | 103 } |
| 96 _addRangeHeader(request, from, to); | 104 _addRangeHeader(request, from, to); |
| 97 return request.close(); | 105 return request.close(); |
| 98 }) | 106 }) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 var toStr = to != null ? '$to' : ''; | 295 var toStr = to != null ? '$to' : ''; |
| 288 if (fromStr.isNotEmpty || toStr.isNotEmpty) { | 296 if (fromStr.isNotEmpty || toStr.isNotEmpty) { |
| 289 request.headers.set(HttpHeaders.RANGE, 'bytes=$fromStr-$toStr'); | 297 request.headers.set(HttpHeaders.RANGE, 'bytes=$fromStr-$toStr'); |
| 290 } | 298 } |
| 291 } | 299 } |
| 292 | 300 |
| 293 const CERTIFICATE = "localhost_cert"; | 301 const CERTIFICATE = "localhost_cert"; |
| 294 | 302 |
| 295 | 303 |
| 296 void setupSecure() { | 304 void setupSecure() { |
| 297 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); | 305 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 298 SecureSocket.initialize(database: certificateDatabase, | 306 |
| 299 password: 'dartdart'); | 307 serverContext = new SecurityContext() |
| 308 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
| 309 ..usePrivateKey(localFile('certificates/server_key.pem'), |
| 310 password: 'dartdart'); |
| 311 |
| 312 clientContext = new SecurityContext() |
| 313 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); |
| 300 } | 314 } |
| OLD | NEW |