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 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 import "dart:uri"; | 9 import "dart:uri"; |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 response.close(); | 50 response.close(); |
51 } | 51 } |
52 ); | 52 ); |
53 addRequestHandler( | 53 addRequestHandler( |
54 "/location", | 54 "/location", |
55 (HttpRequest request, HttpResponse response) { | 55 (HttpRequest request, HttpResponse response) { |
56 response.close(); | 56 response.close(); |
57 } | 57 } |
58 ); | 58 ); |
59 | 59 |
| 60 // Setup redirects with relative url. |
| 61 addRequestHandler( |
| 62 "/redirectUrl", |
| 63 (HttpRequest request, HttpResponse response) { |
| 64 response.headers.set(HttpHeaders.LOCATION, "/some/relativeUrl"); |
| 65 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 66 response.close(); |
| 67 } |
| 68 ); |
| 69 |
| 70 addRequestHandler( |
| 71 "/some/redirectUrl", |
| 72 (HttpRequest request, HttpResponse response) { |
| 73 response.headers.set(HttpHeaders.LOCATION, "relativeUrl"); |
| 74 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 75 response.close(); |
| 76 } |
| 77 ); |
| 78 |
| 79 addRequestHandler( |
| 80 "/some/relativeUrl", |
| 81 (HttpRequest request, HttpResponse response) { |
| 82 response.close(); |
| 83 } |
| 84 ); |
| 85 |
| 86 addRequestHandler( |
| 87 "/redirectUrl2", |
| 88 (HttpRequest request, HttpResponse response) { |
| 89 response.headers.set(HttpHeaders.LOCATION, "location"); |
| 90 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 91 response.close(); |
| 92 } |
| 93 ); |
| 94 |
| 95 addRequestHandler( |
| 96 "/redirectUrl3", |
| 97 (HttpRequest request, HttpResponse response) { |
| 98 response.headers.set(HttpHeaders.LOCATION, "./location"); |
| 99 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 100 response.close(); |
| 101 } |
| 102 ); |
| 103 |
| 104 addRequestHandler( |
| 105 "/redirectUrl4", |
| 106 (HttpRequest request, HttpResponse response) { |
| 107 response.headers.set(HttpHeaders.LOCATION, "./a/b/../../location"); |
| 108 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 109 response.close(); |
| 110 } |
| 111 ); |
| 112 |
| 113 addRequestHandler( |
| 114 "/redirectUrl5", |
| 115 (HttpRequest request, HttpResponse response) { |
| 116 response.headers.set(HttpHeaders.LOCATION, |
| 117 "//127.0.0.1:${server.port}/location"); |
| 118 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 119 response.close(); |
| 120 } |
| 121 ); |
| 122 |
60 // Setup redirect chain. | 123 // Setup redirect chain. |
61 int n = 1; | 124 int n = 1; |
62 addRedirectHandler(n++, HttpStatus.MOVED_PERMANENTLY); | 125 addRedirectHandler(n++, HttpStatus.MOVED_PERMANENTLY); |
63 addRedirectHandler(n++, HttpStatus.MOVED_TEMPORARILY); | 126 addRedirectHandler(n++, HttpStatus.MOVED_TEMPORARILY); |
64 addRedirectHandler(n++, HttpStatus.SEE_OTHER); | 127 addRedirectHandler(n++, HttpStatus.SEE_OTHER); |
65 addRedirectHandler(n++, HttpStatus.TEMPORARY_REDIRECT); | 128 addRedirectHandler(n++, HttpStatus.TEMPORARY_REDIRECT); |
66 for (int i = n; i < 10; i++) { | 129 for (int i = n; i < 10; i++) { |
67 addRedirectHandler(i, HttpStatus.MOVED_PERMANENTLY); | 130 addRedirectHandler(i, HttpStatus.MOVED_PERMANENTLY); |
68 } | 131 } |
69 | 132 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 (_) {}, | 426 (_) {}, |
364 onDone: () { | 427 onDone: () { |
365 Expect.equals(1, response.redirects.length); | 428 Expect.equals(1, response.redirects.length); |
366 server.close(); | 429 server.close(); |
367 client.close(); | 430 client.close(); |
368 }); | 431 }); |
369 }); | 432 }); |
370 }); | 433 }); |
371 } | 434 } |
372 | 435 |
| 436 void testRedirectRelativeUrl() { |
| 437 testPath(String path) { |
| 438 setupServer().then((server) { |
| 439 HttpClient client = new HttpClient(); |
| 440 |
| 441 print(path); |
| 442 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}$path")) |
| 443 .then((request) => request.close()) |
| 444 .then((response) { |
| 445 response.listen( |
| 446 (_) {}, |
| 447 onDone: () { |
| 448 Expect.equals(HttpStatus.OK, response.statusCode); |
| 449 Expect.equals(1, response.redirects.length); |
| 450 server.close(); |
| 451 client.close(); |
| 452 }); |
| 453 }); |
| 454 }); |
| 455 } |
| 456 testPath("/redirectUrl"); |
| 457 testPath("/some/redirectUrl"); |
| 458 testPath("/redirectUrl2"); |
| 459 testPath("/redirectUrl3"); |
| 460 testPath("/redirectUrl4"); |
| 461 testPath("/redirectUrl5"); |
| 462 } |
| 463 |
373 main() { | 464 main() { |
374 testManualRedirect(); | 465 testManualRedirect(); |
375 testManualRedirectWithHeaders(); | 466 testManualRedirectWithHeaders(); |
376 testAutoRedirect(); | 467 testAutoRedirect(); |
377 testAutoRedirectWithHeaders(); | 468 testAutoRedirectWithHeaders(); |
378 testAutoRedirect301POST(); | 469 testAutoRedirect301POST(); |
379 testAutoRedirect303POST(); | 470 testAutoRedirect303POST(); |
380 testAutoRedirectLimit(); | 471 testAutoRedirectLimit(); |
381 testRedirectLoop(); | 472 testRedirectLoop(); |
382 testRedirectClosingConnection(); | 473 testRedirectClosingConnection(); |
| 474 testRedirectRelativeUrl(); |
383 } | 475 } |
OLD | NEW |