| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 void testManualRedirect() { | 85 void testManualRedirect() { |
| 86 HttpServer server = setupServer(); | 86 HttpServer server = setupServer(); |
| 87 HttpClient client = new HttpClient(); | 87 HttpClient client = new HttpClient(); |
| 88 | 88 |
| 89 int redirectCount = 0; | 89 int redirectCount = 0; |
| 90 HttpClientConnection conn = | 90 HttpClientConnection conn = |
| 91 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/1")); | 91 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/1")); |
| 92 conn.followRedirects = false; | 92 conn.followRedirects = false; |
| 93 conn.onResponse = (HttpClientResponse response) { | 93 conn.onResponse = (HttpClientResponse response) { |
| 94 response.inputStream.onData = () => response.inputStream.read(); | 94 response.inputStream.onData = response.inputStream.read; |
| 95 response.inputStream.onClosed = () { | 95 response.inputStream.onClosed = () { |
| 96 redirectCount++; | 96 redirectCount++; |
| 97 if (redirectCount < 10) { | 97 if (redirectCount < 10) { |
| 98 Expect.isTrue(response.isRedirect); | 98 Expect.isTrue(response.isRedirect); |
| 99 checkRedirects(redirectCount, conn); | 99 checkRedirects(redirectCount, conn); |
| 100 conn.redirect(); | 100 conn.redirect(); |
| 101 } else { | 101 } else { |
| 102 Expect.equals(HttpStatus.NOT_FOUND, response.statusCode); | 102 Expect.equals(HttpStatus.NOT_FOUND, response.statusCode); |
| 103 server.close(); | 103 server.close(); |
| 104 client.shutdown(); | 104 client.shutdown(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 client.shutdown(); | 172 client.shutdown(); |
| 173 }; | 173 }; |
| 174 } | 174 } |
| 175 | 175 |
| 176 main() { | 176 main() { |
| 177 testManualRedirect(); | 177 testManualRedirect(); |
| 178 testAutoRedirect(); | 178 testAutoRedirect(); |
| 179 testAutoRedirectLimit(); | 179 testAutoRedirectLimit(); |
| 180 testRedirectLoop(); | 180 testRedirectLoop(); |
| 181 } | 181 } |
| OLD | NEW |