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

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

Issue 11821046: Always set content length to 0 on redirect requests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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) 2012, 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 "dart:io"; 6 import "dart:io";
7 import "dart:uri"; 7 import "dart:uri";
8 8
9 HttpServer setupServer() { 9 HttpServer setupServer() {
10 HttpServer server = new HttpServer(); 10 HttpServer server = new HttpServer();
11 server.listen("127.0.0.1", 0, backlog: 5); 11 server.listen("127.0.0.1", 0, backlog: 5);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 (HttpRequest request, HttpResponse response) { 103 (HttpRequest request, HttpResponse response) {
104 Expect.fail("Redirect of POST should not happen"); 104 Expect.fail("Redirect of POST should not happen");
105 } 105 }
106 ); 106 );
107 107
108 // Setup redirect for 303 where POST should turn into GET. 108 // Setup redirect for 303 where POST should turn into GET.
109 server.addRequestHandler( 109 server.addRequestHandler(
110 (HttpRequest request) => request.path == "/303src", 110 (HttpRequest request) => request.path == "/303src",
111 (HttpRequest request, HttpResponse response) { 111 (HttpRequest request, HttpResponse response) {
112 Expect.equals("POST", request.method); 112 Expect.equals("POST", request.method);
113 response.headers.set(HttpHeaders.LOCATION, 113 Expect.equals(10, request.contentLength);
114 "http://127.0.0.1:${server.port}/303target"); 114 request.inputStream.onData = request.inputStream.read;
115 response.statusCode = HttpStatus.SEE_OTHER; 115 request.inputStream.onClosed = () {
116 response.outputStream.close(); 116 response.headers.set(HttpHeaders.LOCATION,
117 "http://127.0.0.1:${server.port}/303target");
118 response.statusCode = HttpStatus.SEE_OTHER;
119 response.outputStream.close();
120 };
117 } 121 }
118 ); 122 );
119 server.addRequestHandler( 123 server.addRequestHandler(
120 (HttpRequest request) => request.path == "/303target", 124 (HttpRequest request) => request.path == "/303target",
121 (HttpRequest request, HttpResponse response) { 125 (HttpRequest request, HttpResponse response) {
122 Expect.equals("GET", request.method); 126 Expect.equals("GET", request.method);
123 response.outputStream.close(); 127 response.outputStream.close();
124 } 128 }
125 ); 129 );
126 130
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 284 }
281 285
282 void testAutoRedirect303POST() { 286 void testAutoRedirect303POST() {
283 HttpServer server = setupServer(); 287 HttpServer server = setupServer();
284 HttpClient client = new HttpClient(); 288 HttpClient client = new HttpClient();
285 289
286 var requestCount = 0; 290 var requestCount = 0;
287 291
288 void onRequest(HttpClientRequest request) { 292 void onRequest(HttpClientRequest request) {
289 requestCount++; 293 requestCount++;
294 request.contentLength = 10;
295 request.outputStream.write(new List<int>.fixedLength(10, fill: 0));
290 request.outputStream.close(); 296 request.outputStream.close();
291 }; 297 };
292 298
293 void onResponse(HttpClientResponse response) { 299 void onResponse(HttpClientResponse response) {
294 Expect.equals(HttpStatus.OK, response.statusCode); 300 Expect.equals(HttpStatus.OK, response.statusCode);
295 response.inputStream.onData = 301 response.inputStream.onData =
296 () => Expect.fail("Response data not expected"); 302 () => Expect.fail("Response data not expected");
297 response.inputStream.onClosed = () { 303 response.inputStream.onClosed = () {
298 Expect.equals(1, requestCount); 304 Expect.equals(1, requestCount);
299 server.close(); 305 server.close();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 main() { 355 main() {
350 testManualRedirect(); 356 testManualRedirect();
351 testManualRedirectWithHeaders(); 357 testManualRedirectWithHeaders();
352 testAutoRedirect(); 358 testAutoRedirect();
353 testAutoRedirectWithHeaders(); 359 testAutoRedirectWithHeaders();
354 testAutoRedirect301POST(); 360 testAutoRedirect301POST();
355 testAutoRedirect303POST(); 361 testAutoRedirect303POST();
356 testAutoRedirectLimit(); 362 testAutoRedirectLimit();
357 testRedirectLoop(); 363 testRedirectLoop();
358 } 364 }
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