OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 import "dart:io"; | |
7 | |
8 void testCookies() { | |
9 var cookies = [{'abc': 'def'}, | |
10 {'ABC': 'DEF'}, | |
11 {'Abc': 'Def'}, | |
12 {'Abc': 'Def', 'SID': 'sffFSDF4FsdfF56765'}]; | |
13 | |
14 HttpServer.bind("127.0.0.1", 0).then((server) { | |
15 server.listen( | |
Bill Hesse
2013/06/04 08:30:14
Should we show people how to indent closures less,
Søren Gjesse
2013/06/04 08:54:45
Done - I did not see any other places.
| |
16 (HttpRequest request) { | |
17 // Collect the cookies in a map. | |
18 var cookiesMap = {}; | |
19 request.cookies.forEach((c) => cookiesMap[c.name] = c.value); | |
20 int index = int.parse(request.uri.path.substring(1)); | |
21 Expect.mapEquals(cookies[index], cookiesMap); | |
22 // Return the same cookies to the client. | |
23 cookiesMap.forEach((k, v) { | |
24 request.response.cookies.add(new Cookie(k, v)); | |
25 }); | |
26 request.response.close(); | |
27 }); | |
28 | |
29 int count = 0; | |
30 HttpClient client = new HttpClient(); | |
31 for (int i = 0; i < cookies.length; i++) { | |
32 client.get("127.0.0.1", server.port, "/$i") | |
33 .then((request) { | |
34 // Send the cookies to the server. | |
35 cookies[i].forEach((k, v) { | |
36 request.cookies.add(new Cookie(k, v)); | |
37 }); | |
38 return request.close(); | |
39 }) | |
40 .then((response) { | |
41 // Expect the same cookies back. | |
42 var cookiesMap = {}; | |
43 response.cookies.forEach((c) => cookiesMap[c.name] = c.value); | |
44 Expect.mapEquals(cookies[i], cookiesMap); | |
45 response.listen( | |
46 (d) {}, | |
47 onDone: () { | |
48 if (++count == cookies.length) { | |
49 client.close(); | |
50 server.close(); | |
51 } | |
52 }); | |
53 }) | |
54 .catchError((e) { | |
55 String msg = "Unexpected error $e"; | |
56 var trace = getAttachedStackTrace(e); | |
57 if (trace != null) msg += "\nStackTrace: $trace"; | |
58 Expect.fail(msg); | |
59 }); | |
60 } | |
61 }); | |
62 } | |
63 | |
64 void main() { | |
65 testCookies(); | |
66 } | |
OLD | NEW |