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

Side by Side Diff: tests/standalone/io/http_redirect_test.dart

Issue 14988003: Support redirect to relative Uri, as specified by rfc3986#4.2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« sdk/lib/io/http_impl.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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
60 // Setup redirect chain. 104 // Setup redirect chain.
61 int n = 1; 105 int n = 1;
62 addRedirectHandler(n++, HttpStatus.MOVED_PERMANENTLY); 106 addRedirectHandler(n++, HttpStatus.MOVED_PERMANENTLY);
63 addRedirectHandler(n++, HttpStatus.MOVED_TEMPORARILY); 107 addRedirectHandler(n++, HttpStatus.MOVED_TEMPORARILY);
64 addRedirectHandler(n++, HttpStatus.SEE_OTHER); 108 addRedirectHandler(n++, HttpStatus.SEE_OTHER);
65 addRedirectHandler(n++, HttpStatus.TEMPORARY_REDIRECT); 109 addRedirectHandler(n++, HttpStatus.TEMPORARY_REDIRECT);
66 for (int i = n; i < 10; i++) { 110 for (int i = n; i < 10; i++) {
67 addRedirectHandler(i, HttpStatus.MOVED_PERMANENTLY); 111 addRedirectHandler(i, HttpStatus.MOVED_PERMANENTLY);
68 } 112 }
69 113
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 (_) {}, 407 (_) {},
364 onDone: () { 408 onDone: () {
365 Expect.equals(1, response.redirects.length); 409 Expect.equals(1, response.redirects.length);
366 server.close(); 410 server.close();
367 client.close(); 411 client.close();
368 }); 412 });
369 }); 413 });
370 }); 414 });
371 } 415 }
372 416
417 void testRedirectRelativeUrl() {
418 setupServer().then((server) {
419 HttpClient client = new HttpClient();
420
421 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/redirectUrl"))
422 .then((request) => request.close())
423 .then((response) {
424 response.listen(
425 (_) {},
426 onDone: () {
427 Expect.equals(HttpStatus.OK, response.statusCode);
428 Expect.equals(1, response.redirects.length);
429 server.close();
430 client.close();
431 });
432 });
433 });
434
435 setupServer().then((server) {
436 HttpClient client = new HttpClient();
437
438 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/some/redirectUrl"))
439 .then((request) => request.close())
440 .then((response) {
441 response.listen(
442 (_) {},
443 onDone: () {
444 Expect.equals(HttpStatus.OK, response.statusCode);
445 Expect.equals(1, response.redirects.length);
446 server.close();
447 client.close();
448 });
449 });
450 });
451
452 setupServer().then((server) {
453 HttpClient client = new HttpClient();
454
455 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/redirectUrl2"))
456 .then((request) => request.close())
457 .then((response) {
458 response.listen(
459 (_) {},
460 onDone: () {
461 Expect.equals(HttpStatus.OK, response.statusCode);
462 Expect.equals(1, response.redirects.length);
463 server.close();
464 client.close();
465 });
466 });
467 });
468
469 setupServer().then((server) {
470 HttpClient client = new HttpClient();
471
472 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/redirectUrl3"))
473 .then((request) => request.close())
474 .then((response) {
475 response.listen(
476 (_) {},
477 onDone: () {
478 Expect.equals(HttpStatus.OK, response.statusCode);
479 Expect.equals(1, response.redirects.length);
480 server.close();
481 client.close();
482 });
483 });
484 });
485 }
486
373 main() { 487 main() {
374 testManualRedirect(); 488 testManualRedirect();
375 testManualRedirectWithHeaders(); 489 testManualRedirectWithHeaders();
376 testAutoRedirect(); 490 testAutoRedirect();
377 testAutoRedirectWithHeaders(); 491 testAutoRedirectWithHeaders();
378 testAutoRedirect301POST(); 492 testAutoRedirect301POST();
379 testAutoRedirect303POST(); 493 testAutoRedirect303POST();
380 testAutoRedirectLimit(); 494 testAutoRedirectLimit();
381 testRedirectLoop(); 495 testRedirectLoop();
382 testRedirectClosingConnection(); 496 testRedirectClosingConnection();
497 testRedirectRelativeUrl();
383 } 498 }
OLDNEW
« sdk/lib/io/http_impl.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698