| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 HttpServer server = setupServer(); | 94 HttpServer server = setupServer(); |
| 95 HttpClient client = new HttpClient(); | 95 HttpClient client = new HttpClient(); |
| 96 | 96 |
| 97 HttpClientConnection conn = | 97 HttpClientConnection conn = |
| 98 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/1")); | 98 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/1")); |
| 99 conn.onResponse = (HttpClientResponse response) { | 99 conn.onResponse = (HttpClientResponse response) { |
| 100 response.inputStream.onData = () => Expect.fail("Response not expected"); | 100 response.inputStream.onData = () => Expect.fail("Response not expected"); |
| 101 response.inputStream.onClosed = () => Expect.fail("Response not expected"); | 101 response.inputStream.onClosed = () => Expect.fail("Response not expected"); |
| 102 }; | 102 }; |
| 103 conn.onError = (e) { | 103 conn.onError = (e) { |
| 104 Expect.isTrue(e is RedirectLimitExceeded); | 104 Expect.isTrue(e is RedirectLimitExceededException); |
| 105 Expect.equals(5, e.redirects.length); | 105 Expect.equals(5, e.redirects.length); |
| 106 server.close(); | 106 server.close(); |
| 107 client.shutdown(); | 107 client.shutdown(); |
| 108 }; | 108 }; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void testRedirectLoop() { | 111 void testRedirectLoop() { |
| 112 HttpServer server = setupServer(); | 112 HttpServer server = setupServer(); |
| 113 HttpClient client = new HttpClient(); | 113 HttpClient client = new HttpClient(); |
| 114 | 114 |
| 115 int redirectCount = 0; | 115 int redirectCount = 0; |
| 116 HttpClientConnection conn = | 116 HttpClientConnection conn = |
| 117 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/A")); | 117 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}/A")); |
| 118 conn.onResponse = (HttpClientResponse response) { | 118 conn.onResponse = (HttpClientResponse response) { |
| 119 response.inputStream.onData = () => Expect.fail("Response not expected"); | 119 response.inputStream.onData = () => Expect.fail("Response not expected"); |
| 120 response.inputStream.onClosed = () => Expect.fail("Response not expected"); | 120 response.inputStream.onClosed = () => Expect.fail("Response not expected"); |
| 121 }; | 121 }; |
| 122 conn.onError = (e) { | 122 conn.onError = (e) { |
| 123 Expect.isTrue(e is RedirectLoop); | 123 Expect.isTrue(e is RedirectLoopException); |
| 124 Expect.equals(2, e.redirects.length); | 124 Expect.equals(2, e.redirects.length); |
| 125 server.close(); | 125 server.close(); |
| 126 client.shutdown(); | 126 client.shutdown(); |
| 127 }; | 127 }; |
| 128 } | 128 } |
| 129 | 129 |
| 130 main() { | 130 main() { |
| 131 testManualRedirect(); | 131 testManualRedirect(); |
| 132 testAutoRedirect(); | 132 testAutoRedirect(); |
| 133 testRedirectLoop(); | 133 testRedirectLoop(); |
| 134 } | 134 } |
| OLD | NEW |