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

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: 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
« 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 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("http://127.0.0.1:${server.port}/${number + 1}");
36 "http://127.0.0.1:${server.port}/${number + 1}");
37 response.statusCode = statusCode;
38 response.close();
39 }); 36 });
40 } 37 }
41 38
42 // Setup simple redirect. 39 // Setup simple redirect.
43 addRequestHandler( 40 addRequestHandler(
44 "/redirect", 41 "/redirect",
45 (HttpRequest request, HttpResponse response) { 42 (HttpRequest request, HttpResponse response) {
46 response.headers.set(HttpHeaders.LOCATION, 43 response.redirect("http://127.0.0.1:${server.port}/location",
47 "http://127.0.0.1:${server.port}/location"); 44 HttpStatus.MOVED_PERMANENTLY);
48 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
49 response.close();
50 } 45 }
51 ); 46 );
52 addRequestHandler( 47 addRequestHandler(
53 "/location", 48 "/location",
54 (HttpRequest request, HttpResponse response) { 49 (HttpRequest request, HttpResponse response) {
55 response.close(); 50 response.close();
56 } 51 }
57 ); 52 );
58 53
59 // Setup redirects with relative url. 54 // Setup redirects with relative url.
(...skipping 16 matching lines...) Expand all
76 ); 71 );
77 72
78 addRequestHandler( 73 addRequestHandler(
79 "/some/relativeUrl", 74 "/some/relativeUrl",
80 (HttpRequest request, HttpResponse response) { 75 (HttpRequest request, HttpResponse response) {
81 response.close(); 76 response.close();
82 } 77 }
83 ); 78 );
84 79
85 addRequestHandler( 80 addRequestHandler(
81 "/some/relativeToAbsolute",
82 (HttpRequest request, HttpResponse response) {
83 response.redirect("xxx", HttpStatus.SEE_OTHER);
84 }
85 );
86
87 addRequestHandler(
86 "/redirectUrl2", 88 "/redirectUrl2",
87 (HttpRequest request, HttpResponse response) { 89 (HttpRequest request, HttpResponse response) {
88 response.headers.set(HttpHeaders.LOCATION, "location"); 90 response.headers.set(HttpHeaders.LOCATION, "location");
89 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 91 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
90 response.close(); 92 response.close();
91 } 93 }
92 ); 94 );
93 95
94 addRequestHandler( 96 addRequestHandler(
95 "/redirectUrl3", 97 "/redirectUrl3",
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 }); 451 });
450 } 452 }
451 testPath("/redirectUrl"); 453 testPath("/redirectUrl");
452 testPath("/some/redirectUrl"); 454 testPath("/some/redirectUrl");
453 testPath("/redirectUrl2"); 455 testPath("/redirectUrl2");
454 testPath("/redirectUrl3"); 456 testPath("/redirectUrl3");
455 testPath("/redirectUrl4"); 457 testPath("/redirectUrl4");
456 testPath("/redirectUrl5"); 458 testPath("/redirectUrl5");
457 } 459 }
458 460
461 void testRedirectRelativeToAbsolute() {
462 setupServer().then((server) {
463 HttpClient client = new HttpClient();
464
465 int redirectCount = 0;
466 handleResponse(HttpClientResponse response) {
467 response.listen(
468 (_) => Expect.fail("Response data not expected"),
469 onDone: () {
470 Expect.equals(HttpStatus.SEE_OTHER, response.statusCode);
471 Expect.equals("http://127.0.0.1:${server.port}/some/xxx",
472 response.headers["Location"][0]);
473 Expect.isTrue(response.isRedirect);
474 server.close();
475 client.close();
476 });
477 }
478 client.getUrl(
479 Uri.parse("http://127.0.0.1:${server.port}/some/relativeToAbsolute"))
480 .then((HttpClientRequest request) {
481 request.followRedirects = false;
482 return request.close();
483 })
484 .then(handleResponse);
485 });
486 }
487
488
Bill Hesse 2013/08/02 08:27:36 One line between functions?
459 main() { 489 main() {
460 testManualRedirect(); 490 testManualRedirect();
461 testManualRedirectWithHeaders(); 491 testManualRedirectWithHeaders();
462 testAutoRedirect(); 492 testAutoRedirect();
463 testAutoRedirectWithHeaders(); 493 testAutoRedirectWithHeaders();
464 testAutoRedirect301POST(); 494 testAutoRedirect301POST();
465 testAutoRedirect303POST(); 495 testAutoRedirect303POST();
466 testAutoRedirectLimit(); 496 testAutoRedirectLimit();
467 testRedirectLoop(); 497 testRedirectLoop();
468 testRedirectClosingConnection(); 498 testRedirectClosingConnection();
469 testRedirectRelativeUrl(); 499 testRedirectRelativeUrl();
500 testRedirectRelativeToAbsolute();
470 } 501 }
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