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

Unified Diff: tests/standalone/io/http_redirect_test.dart

Issue 11498013: Follow the redirect rules from RFC 2616 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_redirect_test.dart
diff --git a/tests/standalone/io/http_redirect_test.dart b/tests/standalone/io/http_redirect_test.dart
index 6bae57e7f6a0b309653d3c1d98a1435ede56ad33..1bad27f0027554ee50a2d8459a4e1696547afa16 100644
--- a/tests/standalone/io/http_redirect_test.dart
+++ b/tests/standalone/io/http_redirect_test.dart
@@ -87,6 +87,43 @@ HttpServer setupServer() {
}
);
+ // Setup redirect for 301 where POST should not redirect.
+ server.addRequestHandler(
+ (HttpRequest request) => request.path == "/301src",
+ (HttpRequest request, HttpResponse response) {
+ Expect.equals("POST", request.method);
+ response.headers.set(HttpHeaders.LOCATION,
+ "http://127.0.0.1:${server.port}/301target");
+ response.statusCode = HttpStatus.MOVED_PERMANENTLY;
+ response.outputStream.close();
+ }
+ );
+ server.addRequestHandler(
+ (HttpRequest request) => request.path == "/301target",
+ (HttpRequest request, HttpResponse response) {
+ Expect.fail("Redirect of POST should not happen");
+ }
+ );
+
+ // Setup redirect for 303 where POST should turn into GET.
+ server.addRequestHandler(
+ (HttpRequest request) => request.path == "/303src",
+ (HttpRequest request, HttpResponse response) {
+ Expect.equals("POST", request.method);
+ response.headers.set(HttpHeaders.LOCATION,
+ "http://127.0.0.1:${server.port}/303target");
+ response.statusCode = HttpStatus.SEE_OTHER;
+ response.outputStream.close();
+ }
+ );
+ server.addRequestHandler(
+ (HttpRequest request) => request.path == "/303target",
+ (HttpRequest request, HttpResponse response) {
+ Expect.equals("GET", request.method);
+ response.outputStream.close();
+ }
+ );
+
return server;
}
@@ -212,6 +249,66 @@ void testAutoRedirectWithHeaders() {
conn.onError = (e) => Expect.fail("Error not expected ($e)");
}
+void testAutoRedirect301POST() {
+ HttpServer server = setupServer();
+ HttpClient client = new HttpClient();
+
+ var requestCount = 0;
+
+ void onRequest(HttpClientRequest request) {
+ requestCount++;
+ request.outputStream.close();
+ };
+
+ void onResponse(HttpClientResponse response) {
+ Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
+ response.inputStream.onData =
+ () => Expect.fail("Response data not expected");
+ response.inputStream.onClosed = () {
+ Expect.equals(1, requestCount);
+ server.close();
+ client.shutdown();
+ };
+ };
+
+ HttpClientConnection conn =
+ client.postUrl(
+ new Uri.fromString("http://127.0.0.1:${server.port}/301src"));
+ conn.onRequest = onRequest;
+ conn.onResponse = onResponse;
+ conn.onError = (e) => Expect.fail("Error not expected ($e)");
+}
+
+void testAutoRedirect303POST() {
+ HttpServer server = setupServer();
+ HttpClient client = new HttpClient();
+
+ var requestCount = 0;
+
+ void onRequest(HttpClientRequest request) {
+ requestCount++;
+ request.outputStream.close();
+ };
+
+ void onResponse(HttpClientResponse response) {
+ Expect.equals(HttpStatus.OK, response.statusCode);
+ response.inputStream.onData =
+ () => Expect.fail("Response data not expected");
+ response.inputStream.onClosed = () {
+ Expect.equals(1, requestCount);
+ server.close();
+ client.shutdown();
+ };
+ };
+
+ HttpClientConnection conn =
+ client.postUrl(
+ new Uri.fromString("http://127.0.0.1:${server.port}/303src"));
+ conn.onRequest = onRequest;
+ conn.onResponse = onResponse;
+ conn.onError = (e) => Expect.fail("Error not expected ($e)");
+}
+
void testAutoRedirectLimit() {
HttpServer server = setupServer();
HttpClient client = new HttpClient();
@@ -254,6 +351,8 @@ main() {
testManualRedirectWithHeaders();
testAutoRedirect();
testAutoRedirectWithHeaders();
+ testAutoRedirect301POST();
+ testAutoRedirect303POST();
testAutoRedirectLimit();
testRedirectLoop();
}
« 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