Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: pkg/http_server/test/utils.dart

Issue 124693002: pkg/http_server: virtual dir test cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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, String path, {String host,
Anders Johnsen 2014/01/05 19:36:08 Please don't change this, this is not the style us
12 String path, 12 bool secure: false, DateTime ifModifiedSince, bool rawPath: false}) {
13 {String host, 13
14 bool secure: false, 14 Uri uri;
15 DateTime ifModifiedSince,
16 bool rawPath: false}) {
17 var uri;
18 if (rawPath) { 15 if (rawPath) {
19 uri = new Uri(scheme: secure ? 'https' : 'http', 16 uri = new Uri(scheme: secure ? 'https' : 'http',
20 host: 'localhost', 17 host: 'localhost',
21 port: port, 18 port: port,
22 path: path); 19 path: path);
23 } else { 20 } else {
24 uri = (secure ? 21 uri = (secure ?
25 new Uri.https('localhost:$port', path) : 22 new Uri.https('localhost:$port', path) :
26 new Uri.http('localhost:$port', path)); 23 new Uri.http('localhost:$port', path));
27 } 24 }
25
28 return new HttpClient().getUrl(uri) 26 return new HttpClient().getUrl(uri)
29 .then((request) { 27 .then((request) {
30 if (host != null) request.headers.host = host; 28 if (host != null) request.headers.host = host;
31 if (ifModifiedSince != null) { 29 if (ifModifiedSince != null) {
32 request.headers.ifModifiedSince = ifModifiedSince; 30 request.headers.ifModifiedSince = ifModifiedSince;
33 } 31 }
34 return request.close(); 32 return request.close();
35 }) 33 })
36 .then((response) => response.drain().then( 34 .then((response) => response.drain().then(
37 (_) => response.statusCode)); 35 (_) => response.statusCode));
38 } 36 }
39 37
40 38
41 Future<HttpHeaders> getHeaders(int port, String path) { 39 Future<HttpHeaders> getHeaders(int port, String path) =>
42 return new HttpClient().get('localhost', port, path) 40 new HttpClient()
41 .get('localhost', port, path)
43 .then((request) => request.close()) 42 .then((request) => request.close())
44 .then((response) => response.drain().then( 43 .then((response) => response.drain().then(
45 (_) => response.headers)); 44 (_) => response.headers));
46 }
47 45
48 46
49 Future<String> getAsString(int port, String path) { 47
50 return new HttpClient().get('localhost', port, path) 48 Future<String> getAsString(int port, String path) =>
49 new HttpClient()
50 .get('localhost', port, path)
51 .then((request) => request.close()) 51 .then((request) => request.close())
52 .then((response) => UTF8.decodeStream(response)); 52 .then((response) => UTF8.decodeStream(response));
53 }
54 53
55 54
56 const CERTIFICATE = "localhost_cert"; 55 const CERTIFICATE = "localhost_cert";
57 56
58 57
59 setupSecure() { 58 void setupSecure() {
60 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); 59 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
61 SecureSocket.initialize(database: certificateDatabase, 60 SecureSocket.initialize(database: certificateDatabase,
62 password: 'dartdart'); 61 password: 'dartdart');
63 } 62 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | pkg/http_server/test/virtual_directory_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698