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

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

Issue 119453005: Make VirtualDirectory redirect if the directory-path does not end with a tailing slash. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use absolute uri for redirect. 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 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 void testVirtualDir(String name, Future func(Directory dir)) { 14 void testVirtualDir(String name, Future func(Directory dir)) {
15 test(name, () { 15 test(name, () {
16 var dir = Directory.systemTemp.createTempSync('http_server_virtual_'); 16 var dir = Directory.systemTemp.createTempSync('http_server_virtual_');
17 17
18 return func(dir) 18 return func(dir)
19 .whenComplete(() { 19 .whenComplete(() {
20 return dir.delete(recursive: true); 20 return dir.delete(recursive: true);
21 }); 21 });
22 }); 22 });
23 } 23 }
24 24
25 Future<int> getStatusCodeForVirtDir(VirtualDirectory virtualDir, 25 Future<int> getStatusCodeForVirtDir(VirtualDirectory virtualDir,
26 String path, 26 String path,
27 {String host, 27 {String host,
28 bool secure: false, 28 bool secure: false,
29 DateTime ifModifiedSince, 29 DateTime ifModifiedSince,
30 bool rawPath: false}) { 30 bool rawPath: false,
31 bool followRedirects: true}) {
31 return _withServer((server) { 32 return _withServer((server) {
32 33
33 virtualDir.serve(server); 34 virtualDir.serve(server);
34 return getStatusCode(server.port, path, host: host, secure: secure, 35 return getStatusCode(server.port, path, host: host, secure: secure,
35 ifModifiedSince: ifModifiedSince, rawPath: rawPath); 36 ifModifiedSince: ifModifiedSince, rawPath: rawPath,
37 followRedirects: followRedirects);
36 }); 38 });
37 } 39 }
38 40
39 Future<int> getStatusCode(int port, 41 Future<int> getStatusCode(int port,
40 String path, 42 String path,
41 {String host, 43 {String host,
42 bool secure: false, 44 bool secure: false,
43 DateTime ifModifiedSince, 45 DateTime ifModifiedSince,
44 bool rawPath: false}) { 46 bool rawPath: false,
47 bool followRedirects: true}) {
45 Uri uri; 48 Uri uri;
46 if (rawPath) { 49 if (rawPath) {
47 uri = new Uri(scheme: secure ? 'https' : 'http', 50 uri = new Uri(scheme: secure ? 'https' : 'http',
48 host: 'localhost', 51 host: 'localhost',
49 port: port, 52 port: port,
50 path: path); 53 path: path);
51 } else { 54 } else {
52 uri = (secure ? 55 uri = (secure ?
53 new Uri.https('localhost:$port', path) : 56 new Uri.https('localhost:$port', path) :
54 new Uri.http('localhost:$port', path)); 57 new Uri.http('localhost:$port', path));
55 } 58 }
56 59
57 return new HttpClient().getUrl(uri) 60 return new HttpClient().getUrl(uri)
58 .then((request) { 61 .then((request) {
62 if (!followRedirects) request.followRedirects = false;
59 if (host != null) request.headers.host = host; 63 if (host != null) request.headers.host = host;
60 if (ifModifiedSince != null) { 64 if (ifModifiedSince != null) {
61 request.headers.ifModifiedSince = ifModifiedSince; 65 request.headers.ifModifiedSince = ifModifiedSince;
62 } 66 }
63 return request.close(); 67 return request.close();
64 }) 68 })
65 .then((response) => response.drain().then( 69 .then((response) => response.drain().then(
66 (_) => response.statusCode)); 70 (_) => response.statusCode));
67 } 71 }
68 72
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 104
101 105
102 const CERTIFICATE = "localhost_cert"; 106 const CERTIFICATE = "localhost_cert";
103 107
104 108
105 void setupSecure() { 109 void setupSecure() {
106 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); 110 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
107 SecureSocket.initialize(database: certificateDatabase, 111 SecureSocket.initialize(database: certificateDatabase,
108 password: 'dartdart'); 112 password: 'dartdart');
109 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698