| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:crypto'; | 7 import 'dart:crypto'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 | 214 |
| 215 void testLocalServerBasic() { | 215 void testLocalServerBasic() { |
| 216 HttpClient client = new HttpClient(); | 216 HttpClient client = new HttpClient(); |
| 217 | 217 |
| 218 client.authenticate = (Uri url, String scheme, String realm) { | 218 client.authenticate = (Uri url, String scheme, String realm) { |
| 219 client.addCredentials( | 219 client.addCredentials( |
| 220 Uri.parse("http://127.0.0.1/basic"), | 220 Uri.parse("http://127.0.0.1/basic"), |
| 221 "test", | 221 "test", |
| 222 new HttpClientBasicCredentials("test", "test")); | 222 new HttpClientBasicCredentials("test", "test")); |
| 223 return new Future.immediate(true); | 223 return new Future.value(true); |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 HttpClientConnection conn = | 226 HttpClientConnection conn = |
| 227 client.getUrl(Uri.parse("http://127.0.0.1/basic/test")); | 227 client.getUrl(Uri.parse("http://127.0.0.1/basic/test")); |
| 228 conn.onResponse = (HttpClientResponse response) { | 228 conn.onResponse = (HttpClientResponse response) { |
| 229 Expect.equals(HttpStatus.OK, response.statusCode); | 229 Expect.equals(HttpStatus.OK, response.statusCode); |
| 230 response.inputStream.onData = () => response.inputStream.read(); | 230 response.inputStream.onData = () => response.inputStream.read(); |
| 231 response.inputStream.onClosed = () { | 231 response.inputStream.onClosed = () { |
| 232 client.shutdown(); | 232 client.shutdown(); |
| 233 }; | 233 }; |
| 234 }; | 234 }; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void testLocalServerDigest() { | 237 void testLocalServerDigest() { |
| 238 HttpClient client = new HttpClient(); | 238 HttpClient client = new HttpClient(); |
| 239 | 239 |
| 240 client.authenticate = (Uri url, String scheme, String realm) { | 240 client.authenticate = (Uri url, String scheme, String realm) { |
| 241 print("url: $url, scheme: $scheme, realm: $realm"); | 241 print("url: $url, scheme: $scheme, realm: $realm"); |
| 242 client.addCredentials( | 242 client.addCredentials( |
| 243 Uri.parse("http://127.0.0.1/digest"), | 243 Uri.parse("http://127.0.0.1/digest"), |
| 244 "test", | 244 "test", |
| 245 new HttpClientDigestCredentials("test", "test")); | 245 new HttpClientDigestCredentials("test", "test")); |
| 246 return new Future.immediate(true); | 246 return new Future.value(true); |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 HttpClientConnection conn = | 249 HttpClientConnection conn = |
| 250 client.getUrl(Uri.parse("http://127.0.0.1/digest/test")); | 250 client.getUrl(Uri.parse("http://127.0.0.1/digest/test")); |
| 251 conn.onResponse = (HttpClientResponse response) { | 251 conn.onResponse = (HttpClientResponse response) { |
| 252 Expect.equals(HttpStatus.OK, response.statusCode); | 252 Expect.equals(HttpStatus.OK, response.statusCode); |
| 253 response.inputStream.onData = () => response.inputStream.read(); | 253 response.inputStream.onData = () => response.inputStream.read(); |
| 254 response.inputStream.onClosed = () { | 254 response.inputStream.onClosed = () { |
| 255 client.shutdown(); | 255 client.shutdown(); |
| 256 }; | 256 }; |
| 257 }; | 257 }; |
| 258 } | 258 } |
| 259 | 259 |
| 260 main() { | 260 main() { |
| 261 testUrlUserInfo(); | 261 testUrlUserInfo(); |
| 262 testBasicNoCredentials(); | 262 testBasicNoCredentials(); |
| 263 testBasicCredentials(); | 263 testBasicCredentials(); |
| 264 testBasicAuthenticateCallback(); | 264 testBasicAuthenticateCallback(); |
| 265 // These teste are not normally run. They can be used for locally | 265 // These teste are not normally run. They can be used for locally |
| 266 // testing with another web server (e.g. Apache). | 266 // testing with another web server (e.g. Apache). |
| 267 //testLocalServerBasic(); | 267 //testLocalServerBasic(); |
| 268 //testLocalServerDigest(); | 268 //testLocalServerDigest(); |
| 269 } | 269 } |
| OLD | NEW |