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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 #import("dart:isolate"); | 10 #import("dart:isolate"); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 request.headers.set("Host", "www.dartlang.org:"); | 280 request.headers.set("Host", "www.dartlang.org:"); |
281 Expect.equals("www.dartlang.org", request.headers.host); | 281 Expect.equals("www.dartlang.org", request.headers.host); |
282 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, request.headers.port); | 282 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, request.headers.port); |
283 request.headers.set("Host", "www.dartlang.org:1234"); | 283 request.headers.set("Host", "www.dartlang.org:1234"); |
284 Expect.equals("www.dartlang.org", request.headers.host); | 284 Expect.equals("www.dartlang.org", request.headers.host); |
285 Expect.equals(1234, request.headers.port); | 285 Expect.equals(1234, request.headers.port); |
286 request.outputStream.close(); | 286 request.outputStream.close(); |
287 }; | 287 }; |
288 conn.onResponse = (HttpClientResponse response) { | 288 conn.onResponse = (HttpClientResponse response) { |
289 Expect.equals(HttpStatus.OK, response.statusCode); | 289 Expect.equals(HttpStatus.OK, response.statusCode); |
290 httpClient.shutdown(); | 290 response.inputStream.onData = response.inputStream.read; |
291 testServerMain.shutdown(); | 291 response.inputStream.onClosed = () { |
292 completer.complete(true); | 292 httpClient.shutdown(); |
| 293 testServerMain.shutdown(); |
| 294 completer.complete(true); |
| 295 }; |
293 }; | 296 }; |
294 }); | 297 }); |
295 testServerMain.start(); | 298 testServerMain.start(); |
296 return completer.future; | 299 return completer.future; |
297 } | 300 } |
298 | 301 |
299 Future testExpires() { | 302 Future testExpires() { |
300 Completer completer = new Completer(); | 303 Completer completer = new Completer(); |
301 TestServerMain testServerMain = new TestServerMain(); | 304 TestServerMain testServerMain = new TestServerMain(); |
302 testServerMain.setServerStartedHandler((int port) { | 305 testServerMain.setServerStartedHandler((int port) { |
303 int responses = 0; | 306 int responses = 0; |
304 HttpClient httpClient = new HttpClient(); | 307 HttpClient httpClient = new HttpClient(); |
305 | 308 |
306 void processResponse(HttpClientResponse response) { | 309 void processResponse(HttpClientResponse response) { |
307 Expect.equals(HttpStatus.OK, response.statusCode); | 310 Expect.equals(HttpStatus.OK, response.statusCode); |
308 Expect.equals("Fri, 11 Jun 1999 18:46:53 GMT", | 311 Expect.equals("Fri, 11 Jun 1999 18:46:53 GMT", |
309 response.headers["expires"][0]); | 312 response.headers["expires"][0]); |
310 Expect.equals(new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0), | 313 Expect.equals(new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0), |
311 response.headers.expires); | 314 response.headers.expires); |
312 responses++; | 315 response.inputStream.onData = response.inputStream.read; |
313 if (responses == 2) { | 316 response.inputStream.onClosed = () { |
314 httpClient.shutdown(); | 317 responses++; |
315 testServerMain.shutdown(); | 318 if (responses == 2) { |
316 completer.complete(true); | 319 httpClient.shutdown(); |
317 } | 320 testServerMain.shutdown(); |
| 321 completer.complete(true); |
| 322 } |
| 323 }; |
318 } | 324 } |
319 | 325 |
320 HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/expires1"); | 326 HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/expires1"); |
321 conn1.onResponse = (HttpClientResponse response) { | 327 conn1.onResponse = (HttpClientResponse response) { |
322 processResponse(response); | 328 processResponse(response); |
323 }; | 329 }; |
324 HttpClientConnection conn2 = httpClient.get("127.0.0.1", port, "/expires2"); | 330 HttpClientConnection conn2 = httpClient.get("127.0.0.1", port, "/expires2"); |
325 conn2.onResponse = (HttpClientResponse response) { | 331 conn2.onResponse = (HttpClientResponse response) { |
326 processResponse(response); | 332 processResponse(response); |
327 }; | 333 }; |
(...skipping 11 matching lines...) Expand all Loading... |
339 | 345 |
340 void processResponse(HttpClientResponse response) { | 346 void processResponse(HttpClientResponse response) { |
341 Expect.equals(HttpStatus.OK, response.statusCode); | 347 Expect.equals(HttpStatus.OK, response.statusCode); |
342 Expect.equals("text/html; charset=utf-8", | 348 Expect.equals("text/html; charset=utf-8", |
343 response.headers.contentType.toString()); | 349 response.headers.contentType.toString()); |
344 Expect.equals("text/html", response.headers.contentType.value); | 350 Expect.equals("text/html", response.headers.contentType.value); |
345 Expect.equals("text", response.headers.contentType.primaryType); | 351 Expect.equals("text", response.headers.contentType.primaryType); |
346 Expect.equals("html", response.headers.contentType.subType); | 352 Expect.equals("html", response.headers.contentType.subType); |
347 Expect.equals("utf-8", | 353 Expect.equals("utf-8", |
348 response.headers.contentType.parameters["charset"]); | 354 response.headers.contentType.parameters["charset"]); |
349 responses++; | 355 response.inputStream.onData = response.inputStream.read; |
350 if (responses == 2) { | 356 response.inputStream.onClosed = () { |
351 httpClient.shutdown(); | 357 responses++; |
352 testServerMain.shutdown(); | 358 if (responses == 2) { |
353 completer.complete(true); | 359 httpClient.shutdown(); |
354 } | 360 testServerMain.shutdown(); |
| 361 completer.complete(true); |
| 362 } |
| 363 }; |
355 } | 364 } |
356 | 365 |
357 HttpClientConnection conn1 = | 366 HttpClientConnection conn1 = |
358 httpClient.get("127.0.0.1", port, "/contenttype1"); | 367 httpClient.get("127.0.0.1", port, "/contenttype1"); |
359 conn1.onRequest = (HttpClientRequest request) { | 368 conn1.onRequest = (HttpClientRequest request) { |
360 ContentType contentType = new ContentType(); | 369 ContentType contentType = new ContentType(); |
361 contentType.value = "text/html"; | 370 contentType.value = "text/html"; |
362 contentType.parameters["charset"] = "utf-8"; | 371 contentType.parameters["charset"] = "utf-8"; |
363 request.headers.contentType = contentType; | 372 request.headers.contentType = contentType; |
364 request.outputStream.close(); | 373 request.outputStream.close(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 Expect.fail("Unexpected cookie"); | 417 Expect.fail("Unexpected cookie"); |
409 } | 418 } |
410 }); | 419 }); |
411 HttpClientConnection conn2 = | 420 HttpClientConnection conn2 = |
412 httpClient.get("127.0.0.1", port, "/cookie2"); | 421 httpClient.get("127.0.0.1", port, "/cookie2"); |
413 conn2.onRequest = (HttpClientRequest request) { | 422 conn2.onRequest = (HttpClientRequest request) { |
414 request.cookies.add(response.cookies[0]); | 423 request.cookies.add(response.cookies[0]); |
415 request.cookies.add(response.cookies[1]); | 424 request.cookies.add(response.cookies[1]); |
416 request.outputStream.close(); | 425 request.outputStream.close(); |
417 }; | 426 }; |
418 conn2.onResponse = (HttpClientResponse ignored) { | 427 conn2.onResponse = (HttpClientResponse response) { |
419 httpClient.shutdown(); | 428 response.inputStream.onData = response.inputStream.read; |
420 testServerMain.shutdown(); | 429 response.inputStream.onClosed = () { |
421 completer.complete(true); | 430 httpClient.shutdown(); |
| 431 testServerMain.shutdown(); |
| 432 completer.complete(true); |
| 433 }; |
422 }; | 434 }; |
423 }; | 435 }; |
424 }); | 436 }); |
425 testServerMain.start(); | 437 testServerMain.start(); |
426 return completer.future; | 438 return completer.future; |
427 } | 439 } |
428 | 440 |
429 Future testFlush() { | 441 Future testFlush() { |
430 Completer completer = new Completer(); | 442 Completer completer = new Completer(); |
431 TestServerMain testServerMain = new TestServerMain(); | 443 TestServerMain testServerMain = new TestServerMain(); |
432 testServerMain.setServerStartedHandler((int port) { | 444 testServerMain.setServerStartedHandler((int port) { |
433 HttpClient httpClient = new HttpClient(); | 445 HttpClient httpClient = new HttpClient(); |
434 | 446 |
435 HttpClientConnection conn = httpClient.get("127.0.0.1", port, "/flush"); | 447 HttpClientConnection conn = httpClient.get("127.0.0.1", port, "/flush"); |
436 conn.onRequest = (HttpClientRequest request) { | 448 conn.onRequest = (HttpClientRequest request) { |
437 request.outputStream.flush(); | 449 request.outputStream.flush(); |
438 request.outputStream.close(); | 450 request.outputStream.close(); |
439 }; | 451 }; |
440 conn.onResponse = (HttpClientResponse response) { | 452 conn.onResponse = (HttpClientResponse response) { |
441 Expect.equals(HttpStatus.OK, response.statusCode); | 453 Expect.equals(HttpStatus.OK, response.statusCode); |
442 httpClient.shutdown(); | 454 response.inputStream.onData = response.inputStream.read; |
443 testServerMain.shutdown(); | 455 response.inputStream.onClosed = () { |
444 completer.complete(true); | 456 httpClient.shutdown(); |
| 457 testServerMain.shutdown(); |
| 458 completer.complete(true); |
| 459 }; |
445 }; | 460 }; |
446 }); | 461 }); |
447 testServerMain.start(); | 462 testServerMain.start(); |
448 return completer.future; | 463 return completer.future; |
449 } | 464 } |
450 | 465 |
451 void main() { | 466 void main() { |
452 print('testHost()'); | 467 print('testHost()'); |
453 testHost().chain((_) { | 468 testHost().chain((_) { |
454 print('testExpires()'); | 469 print('testExpires()'); |
455 return testExpires().chain((_) { | 470 return testExpires().chain((_) { |
456 print('testContentType()'); | 471 print('testContentType()'); |
457 return testContentType().chain((_) { | 472 return testContentType().chain((_) { |
458 print('testCookies()'); | 473 print('testCookies()'); |
459 return testCookies().chain((_) { | 474 return testCookies().chain((_) { |
460 print('testFlush()'); | 475 print('testFlush()'); |
461 return testFlush(); | 476 return testFlush(); |
462 }); | 477 }); |
463 }); | 478 }); |
464 }); | 479 }); |
465 }).then((_) { | 480 }).then((_) { |
466 print('done'); | 481 print('done'); |
467 }); | 482 }); |
468 } | 483 } |
OLD | NEW |