OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:pub/src/utils.dart'; | 10 import 'package:pub/src/utils.dart'; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 224 } |
225 | 225 |
226 void endPubServe() { | 226 void endPubServe() { |
227 _pubServer.kill(); | 227 _pubServer.kill(); |
228 } | 228 } |
229 | 229 |
230 /// Schedules an HTTP request to the running pub server with [urlPath] and | 230 /// Schedules an HTTP request to the running pub server with [urlPath] and |
231 /// invokes [callback] with the response. | 231 /// invokes [callback] with the response. |
232 /// | 232 /// |
233 /// [root] indicates which server should be accessed, and defaults to "web". | 233 /// [root] indicates which server should be accessed, and defaults to "web". |
234 Future<http.Response> scheduleRequest(String urlPath, {String root}) { | 234 Future<http.Response> scheduleRequest(String urlPath, |
| 235 {String root, Map<String, String> headers}) { |
235 return schedule(() { | 236 return schedule(() { |
236 return http.get(_getServerUrlSync(root, urlPath)); | 237 return http.get(_getServerUrlSync(root, urlPath), headers: headers); |
237 }, "request $urlPath"); | 238 }, "request $urlPath"); |
238 } | 239 } |
239 | 240 |
240 /// Schedules an HTTP request to the running pub server with [urlPath] and | 241 /// Schedules an HTTP request to the running pub server with [urlPath] and |
241 /// verifies that it responds with a body that matches [expectation]. | 242 /// verifies that it responds with a body that matches [expectation]. |
242 /// | 243 /// |
243 /// [expectation] may either be a [Matcher] or a string to match an exact body. | 244 /// [expectation] may either be a [Matcher] or a string to match an exact body. |
244 /// [root] indicates which server should be accessed, and defaults to "web". | 245 /// [root] indicates which server should be accessed, and defaults to "web". |
245 /// [headers] may be either a [Matcher] or a map to match an exact headers map. | 246 /// [headers] may be either a [Matcher] or a map to match an exact headers map. |
246 void requestShouldSucceed(String urlPath, expectation, {String root, headers}) { | 247 void requestShouldSucceed(String urlPath, expectation, {String root, headers}) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 /// included. Unlike [getServerUrl], this should only be called after the ports | 477 /// included. Unlike [getServerUrl], this should only be called after the ports |
477 /// are known. | 478 /// are known. |
478 String _getServerUrlSync([String root, String path]) { | 479 String _getServerUrlSync([String root, String path]) { |
479 if (root == null) root = 'web'; | 480 if (root == null) root = 'web'; |
480 expect(_ports, contains(root)); | 481 expect(_ports, contains(root)); |
481 var url = "http://localhost:${_ports[root]}"; | 482 var url = "http://localhost:${_ports[root]}"; |
482 if (path != null) url = "$url/$path"; | 483 if (path != null) url = "$url/$path"; |
483 return url; | 484 return url; |
484 } | 485 } |
485 | 486 |
OLD | NEW |