| 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 #import("dart:io"); | 5 #import("dart:io"); |
| 6 | 6 |
| 7 const SESSION_ID = "DARTSESSID"; | 7 const SESSION_ID = "DARTSESSID"; |
| 8 | 8 |
| 9 String getSessionId(List<Cookie> cookies) { | 9 String getSessionId(List<Cookie> cookies) { |
| 10 var id = cookies.reduce(null, (last, cookie) { | 10 var id = cookies.reduce(null, (last, cookie) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 var c = new Completer(); | 23 var c = new Completer(); |
| 24 var client = new HttpClient(); | 24 var client = new HttpClient(); |
| 25 var conn = client.get("127.0.0.1", port, "/"); | 25 var conn = client.get("127.0.0.1", port, "/"); |
| 26 conn.onRequest = (request) { | 26 conn.onRequest = (request) { |
| 27 if (session != null) { | 27 if (session != null) { |
| 28 request.cookies.add(new Cookie(SESSION_ID, session)); | 28 request.cookies.add(new Cookie(SESSION_ID, session)); |
| 29 } | 29 } |
| 30 request.outputStream.close(); | 30 request.outputStream.close(); |
| 31 }; | 31 }; |
| 32 conn.onResponse = (response) { | 32 conn.onResponse = (response) { |
| 33 client.shutdown(); | 33 response.inputStream.onData = response.inputStream.read; |
| 34 c.complete(getSessionId(response.cookies)); | 34 response.inputStream.onClosed = () { |
| 35 client.shutdown(); |
| 36 c.complete(getSessionId(response.cookies)); |
| 37 }; |
| 35 }; | 38 }; |
| 36 return c.future; | 39 return c.future; |
| 37 } | 40 } |
| 38 | 41 |
| 39 void testSessions(int sessionCount) { | 42 void testSessions(int sessionCount) { |
| 40 HttpServer server = new HttpServer(); | 43 HttpServer server = new HttpServer(); |
| 41 server.listen("127.0.0.1", 0); | 44 server.listen("127.0.0.1", 0); |
| 42 var sessions = new Set(); | 45 var sessions = new Set(); |
| 43 server.defaultRequestHandler = (request, response) { | 46 server.defaultRequestHandler = (request, response) { |
| 44 sessions.add(request.session().id); | 47 sessions.add(request.session().id); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 server.close(); | 98 server.close(); |
| 96 }); | 99 }); |
| 97 }); | 100 }); |
| 98 }); | 101 }); |
| 99 } | 102 } |
| 100 | 103 |
| 101 void main() { | 104 void main() { |
| 102 testSessions(5); | 105 testSessions(5); |
| 103 testTimeout(5); | 106 testTimeout(5); |
| 104 } | 107 } |
| OLD | NEW |