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

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

Issue 21411003: Add redirect method to HttpResponse (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 4 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
« no previous file with comments | « 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 9
10 Future<HttpServer> setupServer() { 10 Future<HttpServer> setupServer() {
(...skipping 14 matching lines...) Expand all
25 request.response.statusCode = 404; 25 request.response.statusCode = 404;
26 request.response.close(); 26 request.response.close();
27 }); 27 });
28 } 28 }
29 }); 29 });
30 30
31 void addRedirectHandler(int number, int statusCode) { 31 void addRedirectHandler(int number, int statusCode) {
32 addRequestHandler( 32 addRequestHandler(
33 "/$number", 33 "/$number",
34 (HttpRequest request, HttpResponse response) { 34 (HttpRequest request, HttpResponse response) {
35 response.headers.set(HttpHeaders.LOCATION, 35 response.redirect(
36 "http://127.0.0.1:${server.port}/${number + 1}"); 36 Uri.parse("http://127.0.0.1:${server.port}/${number + 1}"));
37 response.statusCode = statusCode;
38 response.close();
39 }); 37 });
40 } 38 }
41 39
42 // Setup simple redirect. 40 // Setup simple redirect.
43 addRequestHandler( 41 addRequestHandler(
44 "/redirect", 42 "/redirect",
45 (HttpRequest request, HttpResponse response) { 43 (HttpRequest request, HttpResponse response) {
46 response.headers.set(HttpHeaders.LOCATION, 44 response.redirect(
47 "http://127.0.0.1:${server.port}/location"); 45 Uri.parse("http://127.0.0.1:${server.port}/location"),
48 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 46 status: HttpStatus.MOVED_PERMANENTLY);
49 response.close();
50 } 47 }
51 ); 48 );
52 addRequestHandler( 49 addRequestHandler(
53 "/location", 50 "/location",
54 (HttpRequest request, HttpResponse response) { 51 (HttpRequest request, HttpResponse response) {
55 response.close(); 52 response.close();
56 } 53 }
57 ); 54 );
58 55
59 // Setup redirects with relative url. 56 // Setup redirects with relative url.
(...skipping 16 matching lines...) Expand all
76 ); 73 );
77 74
78 addRequestHandler( 75 addRequestHandler(
79 "/some/relativeUrl", 76 "/some/relativeUrl",
80 (HttpRequest request, HttpResponse response) { 77 (HttpRequest request, HttpResponse response) {
81 response.close(); 78 response.close();
82 } 79 }
83 ); 80 );
84 81
85 addRequestHandler( 82 addRequestHandler(
83 "/some/relativeToAbsolute",
84 (HttpRequest request, HttpResponse response) {
85 response.redirect(Uri.parse("xxx"), status: HttpStatus.SEE_OTHER);
86 }
87 );
88
89 addRequestHandler(
86 "/redirectUrl2", 90 "/redirectUrl2",
87 (HttpRequest request, HttpResponse response) { 91 (HttpRequest request, HttpResponse response) {
88 response.headers.set(HttpHeaders.LOCATION, "location"); 92 response.headers.set(HttpHeaders.LOCATION, "location");
89 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 93 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
90 response.close(); 94 response.close();
91 } 95 }
92 ); 96 );
93 97
94 addRequestHandler( 98 addRequestHandler(
95 "/redirectUrl3", 99 "/redirectUrl3",
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 }); 453 });
450 } 454 }
451 testPath("/redirectUrl"); 455 testPath("/redirectUrl");
452 testPath("/some/redirectUrl"); 456 testPath("/some/redirectUrl");
453 testPath("/redirectUrl2"); 457 testPath("/redirectUrl2");
454 testPath("/redirectUrl3"); 458 testPath("/redirectUrl3");
455 testPath("/redirectUrl4"); 459 testPath("/redirectUrl4");
456 testPath("/redirectUrl5"); 460 testPath("/redirectUrl5");
457 } 461 }
458 462
463 void testRedirectRelativeToAbsolute() {
464 setupServer().then((server) {
465 HttpClient client = new HttpClient();
466
467 int redirectCount = 0;
468 handleResponse(HttpClientResponse response) {
469 response.listen(
470 (_) => Expect.fail("Response data not expected"),
471 onDone: () {
472 Expect.equals(HttpStatus.SEE_OTHER, response.statusCode);
473 Expect.equals("xxx",
474 response.headers["Location"][0]);
475 Expect.isTrue(response.isRedirect);
476 server.close();
477 client.close();
478 });
479 }
480 client.getUrl(
481 Uri.parse("http://127.0.0.1:${server.port}/some/relativeToAbsolute"))
482 .then((HttpClientRequest request) {
483 request.followRedirects = false;
484 return request.close();
485 })
486 .then(handleResponse);
487 });
488 }
489
490
459 main() { 491 main() {
460 testManualRedirect(); 492 testManualRedirect();
461 testManualRedirectWithHeaders(); 493 testManualRedirectWithHeaders();
462 testAutoRedirect(); 494 testAutoRedirect();
463 testAutoRedirectWithHeaders(); 495 testAutoRedirectWithHeaders();
464 testAutoRedirect301POST(); 496 testAutoRedirect301POST();
465 testAutoRedirect303POST(); 497 testAutoRedirect303POST();
466 testAutoRedirectLimit(); 498 testAutoRedirectLimit();
467 testRedirectLoop(); 499 testRedirectLoop();
468 testRedirectClosingConnection(); 500 testRedirectClosingConnection();
469 testRedirectRelativeUrl(); 501 testRedirectRelativeUrl();
502 testRedirectRelativeToAbsolute();
470 } 503 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698