OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "package:expect/expect.dart"; |
| 6 import "package:async_helper/async_helper.dart"; |
| 7 import "dart:async"; |
| 8 import "dart:io"; |
| 9 |
| 10 const PATH = '/path?a=b#c'; |
| 11 |
| 12 void test(String expected, Map headers) { |
| 13 asyncStart(); |
| 14 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 15 expected = expected.replaceAll('%PORT', server.port.toString()); |
| 16 server.listen((request) { |
| 17 Expect.equals("$expected$PATH", |
| 18 request.requestedUri.toString()); |
| 19 request.response.close(); |
| 20 }); |
| 21 HttpClient client = new HttpClient(); |
| 22 client.get("localhost", server.port, PATH) |
| 23 .then((request) { |
| 24 for (var v in headers.keys) { |
| 25 if (headers[v] != null) { |
| 26 request.headers.set(v, headers[v]); |
| 27 } else { |
| 28 request.headers.removeAll(v); |
| 29 } |
| 30 } |
| 31 return request.close(); |
| 32 }) |
| 33 .then((response) => response.drain()) |
| 34 .then((_) { |
| 35 server.close(); |
| 36 asyncEnd(); |
| 37 }); |
| 38 }); |
| 39 } |
| 40 |
| 41 |
| 42 void main() { |
| 43 test('http://localhost:%PORT', {}); |
| 44 test('https://localhost:%PORT', {'x-forwarded-proto': 'https'}); |
| 45 test('ws://localhost:%PORT', {'x-forwarded-proto': 'ws'}); |
| 46 test('http://my-host:321', {'x-forwarded-host': 'my-host:321'}); |
| 47 test('http://127.0.0.1:%PORT', {'host': null}); |
| 48 } |
| 49 |
OLD | NEW |