OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:crypto'; | 6 import 'dart:crypto'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 import 'dart:utf'; | 10 import 'dart:utf'; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 void testBasicNoCredentials() { | 92 void testBasicNoCredentials() { |
93 setupServer().then((server) { | 93 setupServer().then((server) { |
94 HttpClient client = new HttpClient(); | 94 HttpClient client = new HttpClient(); |
95 | 95 |
96 Future makeRequest(Uri url) { | 96 Future makeRequest(Uri url) { |
97 return client.getUrl(url) | 97 return client.getUrl(url) |
98 .then((HttpClientRequest request) => request.close()) | 98 .then((HttpClientRequest request) => request.close()) |
99 .then((HttpClientResponse response) { | 99 .then((HttpClientResponse response) { |
100 Expect.equals(HttpStatus.UNAUTHORIZED, response.statusCode); | 100 Expect.equals(HttpStatus.UNAUTHORIZED, response.statusCode); |
101 return response.reduce(null, (x, y) {}); | 101 return response.fold(null, (x, y) {}); |
102 }); | 102 }); |
103 } | 103 } |
104 | 104 |
105 var futures = []; | 105 var futures = []; |
106 for (int i = 0; i < 5; i++) { | 106 for (int i = 0; i < 5; i++) { |
107 futures.add( | 107 futures.add( |
108 makeRequest( | 108 makeRequest( |
109 Uri.parse("http://127.0.0.1:${server.port}/test$i"))); | 109 Uri.parse("http://127.0.0.1:${server.port}/test$i"))); |
110 futures.add( | 110 futures.add( |
111 makeRequest( | 111 makeRequest( |
112 Uri.parse( | 112 Uri.parse( |
113 "http://127.0.0.1:${server.port}/test$i/xxx"))); | 113 "http://127.0.0.1:${server.port}/test$i/xxx"))); |
114 } | 114 } |
115 Future.wait(futures).then((_) { | 115 Future.wait(futures).then((_) { |
116 server.shutdown(); | 116 server.shutdown(); |
117 client.close(); | 117 client.close(); |
118 }); | 118 }); |
119 }); | 119 }); |
120 } | 120 } |
121 | 121 |
122 void testBasicCredentials() { | 122 void testBasicCredentials() { |
123 setupServer().then((server) { | 123 setupServer().then((server) { |
124 HttpClient client = new HttpClient(); | 124 HttpClient client = new HttpClient(); |
125 | 125 |
126 Future makeRequest(Uri url) { | 126 Future makeRequest(Uri url) { |
127 return client.getUrl(url) | 127 return client.getUrl(url) |
128 .then((HttpClientRequest request) => request.close()) | 128 .then((HttpClientRequest request) => request.close()) |
129 .then((HttpClientResponse response) { | 129 .then((HttpClientResponse response) { |
130 Expect.equals(HttpStatus.OK, response.statusCode); | 130 Expect.equals(HttpStatus.OK, response.statusCode); |
131 return response.reduce(null, (x, y) {}); | 131 return response.fold(null, (x, y) {}); |
132 }); | 132 }); |
133 } | 133 } |
134 | 134 |
135 for (int i = 0; i < 5; i++) { | 135 for (int i = 0; i < 5; i++) { |
136 client.addCredentials( | 136 client.addCredentials( |
137 Uri.parse("http://127.0.0.1:${server.port}/test$i"), | 137 Uri.parse("http://127.0.0.1:${server.port}/test$i"), |
138 "realm", | 138 "realm", |
139 new HttpClientBasicCredentials("test$i", "test$i")); | 139 new HttpClientBasicCredentials("test$i", "test$i")); |
140 } | 140 } |
141 | 141 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 completer.complete(true); | 174 completer.complete(true); |
175 }); | 175 }); |
176 return completer.future; | 176 return completer.future; |
177 }; | 177 }; |
178 | 178 |
179 Future makeRequest(Uri url) { | 179 Future makeRequest(Uri url) { |
180 return client.getUrl(url) | 180 return client.getUrl(url) |
181 .then((HttpClientRequest request) => request.close()) | 181 .then((HttpClientRequest request) => request.close()) |
182 .then((HttpClientResponse response) { | 182 .then((HttpClientResponse response) { |
183 Expect.equals(HttpStatus.OK, response.statusCode); | 183 Expect.equals(HttpStatus.OK, response.statusCode); |
184 return response.reduce(null, (x, y) {}); | 184 return response.fold(null, (x, y) {}); |
185 }); | 185 }); |
186 } | 186 } |
187 | 187 |
188 List<Future> makeRequests() { | 188 List<Future> makeRequests() { |
189 var futures = []; | 189 var futures = []; |
190 for (int i = 0; i < 5; i++) { | 190 for (int i = 0; i < 5; i++) { |
191 futures.add( | 191 futures.add( |
192 makeRequest( | 192 makeRequest( |
193 Uri.parse("http://127.0.0.1:${server.port}/test$i"))); | 193 Uri.parse("http://127.0.0.1:${server.port}/test$i"))); |
194 futures.add( | 194 futures.add( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 main() { | 259 main() { |
260 testUrlUserInfo(); | 260 testUrlUserInfo(); |
261 testBasicNoCredentials(); | 261 testBasicNoCredentials(); |
262 testBasicCredentials(); | 262 testBasicCredentials(); |
263 testBasicAuthenticateCallback(); | 263 testBasicAuthenticateCallback(); |
264 // These teste are not normally run. They can be used for locally | 264 // These teste are not normally run. They can be used for locally |
265 // testing with another web server (e.g. Apache). | 265 // testing with another web server (e.g. Apache). |
266 //testLocalServerBasic(); | 266 //testLocalServerBasic(); |
267 //testLocalServerDigest(); | 267 //testLocalServerDigest(); |
268 } | 268 } |
OLD | NEW |