| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #source("../../../../runtime/bin/input_stream.dart"); |
| 6 #source("../../../../runtime/bin/output_stream.dart"); |
| 7 #source("../../../../runtime/bin/chunked_stream.dart"); |
| 8 #source("../../../../runtime/bin/string_stream.dart"); |
| 9 #source("../../../../runtime/bin/stream_util.dart"); |
| 10 #source("../../../../runtime/bin/http.dart"); |
| 11 #source("../../../../runtime/bin/http_impl.dart"); |
| 12 #source("../../../../runtime/bin/http_parser.dart"); |
| 13 #source("../../../../runtime/bin/http_utils.dart"); |
| 14 |
| 15 void testMultiValue() { |
| 16 _HttpHeaders headers = new _HttpHeaders(); |
| 17 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
| 18 headers.add(HttpHeaders.PRAGMA, "pragma1"); |
| 19 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); |
| 20 Expect.equals(1, headers["pragma"].length); |
| 21 Expect.equals(1, headers["Pragma"].length); |
| 22 Expect.equals(1, headers["PRAGMA"].length); |
| 23 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA)); |
| 24 |
| 25 headers.add(HttpHeaders.PRAGMA, "pragma2"); |
| 26 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); |
| 27 Expect.throws(() => headers.value(HttpHeaders.PRAGMA), |
| 28 (e) => e is HttpException); |
| 29 |
| 30 headers.add(HttpHeaders.PRAGMA, ["pragma3", "pragma4"]); |
| 31 Expect.listEquals(["pragma1", "pragma2", "pragma3", "pragma4"], |
| 32 headers[HttpHeaders.PRAGMA]); |
| 33 |
| 34 headers.remove(HttpHeaders.PRAGMA, "pragma3"); |
| 35 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); |
| 36 Expect.listEquals(["pragma1", "pragma2", "pragma4"], |
| 37 headers[HttpHeaders.PRAGMA]); |
| 38 |
| 39 headers.remove(HttpHeaders.PRAGMA, "pragma3"); |
| 40 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); |
| 41 |
| 42 headers.set(HttpHeaders.PRAGMA, "pragma5"); |
| 43 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); |
| 44 |
| 45 headers.set(HttpHeaders.PRAGMA, ["pragma6", "pragma7"]); |
| 46 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); |
| 47 |
| 48 headers.removeAll(HttpHeaders.PRAGMA); |
| 49 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
| 50 } |
| 51 |
| 52 void testExpires() { |
| 53 Date date1 = new Date.withTimeZone( |
| 54 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc()); |
| 55 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; |
| 56 Date date2 = new Date.withTimeZone( |
| 57 2000, Date.AUG, 16, 12, 34, 56, 0, new TimeZone.utc()); |
| 58 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; |
| 59 |
| 60 _HttpHeaders headers = new _HttpHeaders(); |
| 61 Expect.isNull(headers.expires); |
| 62 headers.expires = date1; |
| 63 Expect.equals(date1, headers.expires); |
| 64 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); |
| 65 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
| 66 headers.add(HttpHeaders.EXPIRES, httpDate2); |
| 67 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
| 68 Expect.equals(date2, headers.expires); |
| 69 Expect.equals(httpDate2, headers.value(HttpHeaders.EXPIRES)); |
| 70 headers.set(HttpHeaders.EXPIRES, httpDate1); |
| 71 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
| 72 Expect.equals(date1, headers.expires); |
| 73 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); |
| 74 |
| 75 headers.set(HttpHeaders.EXPIRES, "xxx"); |
| 76 Expect.equals("xxx", headers.value(HttpHeaders.EXPIRES)); |
| 77 Expect.equals(null, headers.expires); |
| 78 } |
| 79 |
| 80 void testHost() { |
| 81 String host = "www.google.com"; |
| 82 _HttpHeaders headers = new _HttpHeaders(); |
| 83 Expect.isNull(headers.host); |
| 84 Expect.isNull(headers.port); |
| 85 headers.host = host; |
| 86 Expect.equals(host, headers.value(HttpHeaders.HOST)); |
| 87 headers.port = 1234; |
| 88 Expect.equals("$host:1234", headers.value(HttpHeaders.HOST)); |
| 89 headers.port = HttpClient.DEFAULT_HTTP_PORT; |
| 90 Expect.equals(host, headers.value(HttpHeaders.HOST)); |
| 91 |
| 92 headers = new _HttpHeaders(); |
| 93 headers.add(HttpHeaders.HOST, host); |
| 94 Expect.equals(host, headers.host); |
| 95 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, headers.port); |
| 96 headers.add(HttpHeaders.HOST, "$host:4567"); |
| 97 Expect.equals(1, headers[HttpHeaders.HOST].length); |
| 98 Expect.equals(host, headers.host); |
| 99 Expect.equals(4567, headers.port); |
| 100 |
| 101 headers = new _HttpHeaders(); |
| 102 headers.add(HttpHeaders.HOST, "$host:xxx"); |
| 103 Expect.equals("$host:xxx", headers.value(HttpHeaders.HOST)); |
| 104 Expect.equals(host, headers.host); |
| 105 Expect.isNull(headers.port); |
| 106 |
| 107 headers = new _HttpHeaders(); |
| 108 headers.add(HttpHeaders.HOST, ":1234"); |
| 109 Expect.equals(":1234", headers.value(HttpHeaders.HOST)); |
| 110 Expect.isNull(headers.host); |
| 111 Expect.equals(1234, headers.port); |
| 112 } |
| 113 |
| 114 main() { |
| 115 testMultiValue(); |
| 116 testExpires(); |
| 117 testHost(); |
| 118 } |
| OLD | NEW |