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:async'; | 5 import 'dart:async'; |
6 import 'dart:math'; | 6 import 'dart:math'; |
7 | 7 |
8 part "../../../sdk/lib/io/input_stream.dart"; | 8 part "../../../sdk/lib/io/input_stream.dart"; |
| 9 part "../../../sdk/lib/io/io_stream_consumer.dart"; |
9 part "../../../sdk/lib/io/output_stream.dart"; | 10 part "../../../sdk/lib/io/output_stream.dart"; |
10 part "../../../sdk/lib/io/chunked_stream.dart"; | |
11 part "../../../sdk/lib/io/string_stream.dart"; | 11 part "../../../sdk/lib/io/string_stream.dart"; |
12 part "../../../sdk/lib/io/stream_util.dart"; | |
13 part "../../../sdk/lib/io/http.dart"; | 12 part "../../../sdk/lib/io/http.dart"; |
14 part "../../../sdk/lib/io/http_headers.dart"; | 13 part "../../../sdk/lib/io/http_headers.dart"; |
15 part "../../../sdk/lib/io/http_impl.dart"; | 14 part "../../../sdk/lib/io/http_impl.dart"; |
16 part "../../../sdk/lib/io/http_parser.dart"; | 15 part "../../../sdk/lib/io/http_parser.dart"; |
17 part "../../../sdk/lib/io/http_utils.dart"; | 16 part "../../../sdk/lib/io/http_utils.dart"; |
| 17 part "../../../sdk/lib/io/socket.dart"; |
18 | 18 |
19 void testMultiValue() { | 19 void testMultiValue() { |
20 _HttpHeaders headers = new _HttpHeaders(); | 20 _HttpHeaders headers = new _HttpHeaders("1.1"); |
21 Expect.isNull(headers[HttpHeaders.PRAGMA]); | 21 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
22 headers.add(HttpHeaders.PRAGMA, "pragma1"); | 22 headers.add(HttpHeaders.PRAGMA, "pragma1"); |
23 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); | 23 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); |
24 Expect.equals(1, headers["pragma"].length); | 24 Expect.equals(1, headers["pragma"].length); |
25 Expect.equals(1, headers["Pragma"].length); | 25 Expect.equals(1, headers["Pragma"].length); |
26 Expect.equals(1, headers["PRAGMA"].length); | 26 Expect.equals(1, headers["PRAGMA"].length); |
27 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA)); | 27 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA)); |
28 | 28 |
29 headers.add(HttpHeaders.PRAGMA, "pragma2"); | 29 headers.add(HttpHeaders.PRAGMA, "pragma2"); |
30 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); | 30 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); |
(...skipping 21 matching lines...) Expand all Loading... |
52 headers.removeAll(HttpHeaders.PRAGMA); | 52 headers.removeAll(HttpHeaders.PRAGMA); |
53 Expect.isNull(headers[HttpHeaders.PRAGMA]); | 53 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
54 } | 54 } |
55 | 55 |
56 void testDate() { | 56 void testDate() { |
57 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); | 57 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); |
58 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; | 58 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; |
59 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); | 59 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); |
60 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; | 60 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; |
61 | 61 |
62 _HttpHeaders headers = new _HttpHeaders(); | 62 _HttpHeaders headers = new _HttpHeaders("1.1"); |
63 Expect.isNull(headers.date); | 63 Expect.isNull(headers.date); |
64 headers.date = date1; | 64 headers.date = date1; |
65 Expect.equals(date1, headers.date); | 65 Expect.equals(date1, headers.date); |
66 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE)); | 66 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE)); |
67 Expect.equals(1, headers[HttpHeaders.DATE].length); | 67 Expect.equals(1, headers[HttpHeaders.DATE].length); |
68 headers.add(HttpHeaders.DATE, httpDate2); | 68 headers.add(HttpHeaders.DATE, httpDate2); |
69 Expect.equals(1, headers[HttpHeaders.DATE].length); | 69 Expect.equals(1, headers[HttpHeaders.DATE].length); |
70 Expect.equals(date2, headers.date); | 70 Expect.equals(date2, headers.date); |
71 Expect.equals(httpDate2, headers.value(HttpHeaders.DATE)); | 71 Expect.equals(httpDate2, headers.value(HttpHeaders.DATE)); |
72 headers.set(HttpHeaders.DATE, httpDate1); | 72 headers.set(HttpHeaders.DATE, httpDate1); |
73 Expect.equals(1, headers[HttpHeaders.DATE].length); | 73 Expect.equals(1, headers[HttpHeaders.DATE].length); |
74 Expect.equals(date1, headers.date); | 74 Expect.equals(date1, headers.date); |
75 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE)); | 75 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE)); |
76 | 76 |
77 headers.set(HttpHeaders.DATE, "xxx"); | 77 headers.set(HttpHeaders.DATE, "xxx"); |
78 Expect.equals("xxx", headers.value(HttpHeaders.DATE)); | 78 Expect.equals("xxx", headers.value(HttpHeaders.DATE)); |
79 Expect.equals(null, headers.date); | 79 Expect.equals(null, headers.date); |
80 } | 80 } |
81 | 81 |
82 void testExpires() { | 82 void testExpires() { |
83 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); | 83 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); |
84 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; | 84 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; |
85 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); | 85 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); |
86 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; | 86 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; |
87 | 87 |
88 _HttpHeaders headers = new _HttpHeaders(); | 88 _HttpHeaders headers = new _HttpHeaders("1.1"); |
89 Expect.isNull(headers.expires); | 89 Expect.isNull(headers.expires); |
90 headers.expires = date1; | 90 headers.expires = date1; |
91 Expect.equals(date1, headers.expires); | 91 Expect.equals(date1, headers.expires); |
92 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); | 92 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); |
93 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); | 93 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
94 headers.add(HttpHeaders.EXPIRES, httpDate2); | 94 headers.add(HttpHeaders.EXPIRES, httpDate2); |
95 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); | 95 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
96 Expect.equals(date2, headers.expires); | 96 Expect.equals(date2, headers.expires); |
97 Expect.equals(httpDate2, headers.value(HttpHeaders.EXPIRES)); | 97 Expect.equals(httpDate2, headers.value(HttpHeaders.EXPIRES)); |
98 headers.set(HttpHeaders.EXPIRES, httpDate1); | 98 headers.set(HttpHeaders.EXPIRES, httpDate1); |
99 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); | 99 Expect.equals(1, headers[HttpHeaders.EXPIRES].length); |
100 Expect.equals(date1, headers.expires); | 100 Expect.equals(date1, headers.expires); |
101 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); | 101 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES)); |
102 | 102 |
103 headers.set(HttpHeaders.EXPIRES, "xxx"); | 103 headers.set(HttpHeaders.EXPIRES, "xxx"); |
104 Expect.equals("xxx", headers.value(HttpHeaders.EXPIRES)); | 104 Expect.equals("xxx", headers.value(HttpHeaders.EXPIRES)); |
105 Expect.equals(null, headers.expires); | 105 Expect.equals(null, headers.expires); |
106 } | 106 } |
107 | 107 |
108 void testIfModifiedSince() { | 108 void testIfModifiedSince() { |
109 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); | 109 DateTime date1 = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0); |
110 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; | 110 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT"; |
111 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); | 111 DateTime date2 = new DateTime.utc(2000, DateTime.AUG, 16, 12, 34, 56, 0); |
112 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; | 112 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT"; |
113 | 113 |
114 _HttpHeaders headers = new _HttpHeaders(); | 114 _HttpHeaders headers = new _HttpHeaders("1.1"); |
115 Expect.isNull(headers.ifModifiedSince); | 115 Expect.isNull(headers.ifModifiedSince); |
116 headers.ifModifiedSince = date1; | 116 headers.ifModifiedSince = date1; |
117 Expect.equals(date1, headers.ifModifiedSince); | 117 Expect.equals(date1, headers.ifModifiedSince); |
118 Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); | 118 Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); |
119 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); | 119 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); |
120 headers.add(HttpHeaders.IF_MODIFIED_SINCE, httpDate2); | 120 headers.add(HttpHeaders.IF_MODIFIED_SINCE, httpDate2); |
121 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); | 121 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); |
122 Expect.equals(date2, headers.ifModifiedSince); | 122 Expect.equals(date2, headers.ifModifiedSince); |
123 Expect.equals(httpDate2, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); | 123 Expect.equals(httpDate2, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); |
124 headers.set(HttpHeaders.IF_MODIFIED_SINCE, httpDate1); | 124 headers.set(HttpHeaders.IF_MODIFIED_SINCE, httpDate1); |
125 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); | 125 Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length); |
126 Expect.equals(date1, headers.ifModifiedSince); | 126 Expect.equals(date1, headers.ifModifiedSince); |
127 Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); | 127 Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE)); |
128 | 128 |
129 headers.set(HttpHeaders.IF_MODIFIED_SINCE, "xxx"); | 129 headers.set(HttpHeaders.IF_MODIFIED_SINCE, "xxx"); |
130 Expect.equals("xxx", headers.value(HttpHeaders.IF_MODIFIED_SINCE)); | 130 Expect.equals("xxx", headers.value(HttpHeaders.IF_MODIFIED_SINCE)); |
131 Expect.equals(null, headers.ifModifiedSince); | 131 Expect.equals(null, headers.ifModifiedSince); |
132 } | 132 } |
133 | 133 |
134 void testHost() { | 134 void testHost() { |
135 String host = "www.google.com"; | 135 String host = "www.google.com"; |
136 _HttpHeaders headers = new _HttpHeaders(); | 136 _HttpHeaders headers = new _HttpHeaders("1.1"); |
137 Expect.isNull(headers.host); | 137 Expect.isNull(headers.host); |
138 Expect.isNull(headers.port); | 138 Expect.isNull(headers.port); |
139 headers.host = host; | 139 headers.host = host; |
140 Expect.equals(host, headers.value(HttpHeaders.HOST)); | 140 Expect.equals(host, headers.value(HttpHeaders.HOST)); |
141 headers.port = 1234; | 141 headers.port = 1234; |
142 Expect.equals("$host:1234", headers.value(HttpHeaders.HOST)); | 142 Expect.equals("$host:1234", headers.value(HttpHeaders.HOST)); |
143 headers.port = HttpClient.DEFAULT_HTTP_PORT; | 143 headers.port = HttpClient.DEFAULT_HTTP_PORT; |
144 Expect.equals(host, headers.value(HttpHeaders.HOST)); | 144 Expect.equals(host, headers.value(HttpHeaders.HOST)); |
145 | 145 |
146 headers = new _HttpHeaders(); | 146 headers = new _HttpHeaders("1.1"); |
147 headers.add(HttpHeaders.HOST, host); | 147 headers.add(HttpHeaders.HOST, host); |
148 Expect.equals(host, headers.host); | 148 Expect.equals(host, headers.host); |
149 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, headers.port); | 149 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, headers.port); |
150 headers.add(HttpHeaders.HOST, "$host:4567"); | 150 headers.add(HttpHeaders.HOST, "$host:4567"); |
151 Expect.equals(1, headers[HttpHeaders.HOST].length); | 151 Expect.equals(1, headers[HttpHeaders.HOST].length); |
152 Expect.equals(host, headers.host); | 152 Expect.equals(host, headers.host); |
153 Expect.equals(4567, headers.port); | 153 Expect.equals(4567, headers.port); |
154 | 154 |
155 headers = new _HttpHeaders(); | 155 headers = new _HttpHeaders("1.1"); |
156 headers.add(HttpHeaders.HOST, "$host:xxx"); | 156 headers.add(HttpHeaders.HOST, "$host:xxx"); |
157 Expect.equals("$host:xxx", headers.value(HttpHeaders.HOST)); | 157 Expect.equals("$host:xxx", headers.value(HttpHeaders.HOST)); |
158 Expect.equals(host, headers.host); | 158 Expect.equals(host, headers.host); |
159 Expect.isNull(headers.port); | 159 Expect.isNull(headers.port); |
160 | 160 |
161 headers = new _HttpHeaders(); | 161 headers = new _HttpHeaders("1.1"); |
162 headers.add(HttpHeaders.HOST, ":1234"); | 162 headers.add(HttpHeaders.HOST, ":1234"); |
163 Expect.equals(":1234", headers.value(HttpHeaders.HOST)); | 163 Expect.equals(":1234", headers.value(HttpHeaders.HOST)); |
164 Expect.isNull(headers.host); | 164 Expect.isNull(headers.host); |
165 Expect.equals(1234, headers.port); | 165 Expect.equals(1234, headers.port); |
166 } | 166 } |
167 | 167 |
168 void testEnumeration() { | 168 void testEnumeration() { |
169 _HttpHeaders headers = new _HttpHeaders(); | 169 _HttpHeaders headers = new _HttpHeaders("1.1"); |
170 Expect.isNull(headers[HttpHeaders.PRAGMA]); | 170 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
171 headers.add("My-Header-1", "value 1"); | 171 headers.add("My-Header-1", "value 1"); |
172 headers.add("My-Header-2", "value 2"); | 172 headers.add("My-Header-2", "value 2"); |
173 headers.add("My-Header-1", "value 3"); | 173 headers.add("My-Header-1", "value 3"); |
174 bool myHeader1 = false; | 174 bool myHeader1 = false; |
175 bool myHeader2 = false; | 175 bool myHeader2 = false; |
176 int totalValues = 0; | 176 int totalValues = 0; |
177 headers.forEach((String name, List<String> values) { | 177 headers.forEach((String name, List<String> values) { |
178 totalValues += values.length; | 178 totalValues += values.length; |
179 if (name == "my-header-1") { | 179 if (name == "my-header-1") { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 280 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
281 contentType = new _ContentType.fromString( | 281 contentType = new _ContentType.fromString( |
282 'text/html; charset=utf-8; xxx="yyy"'); | 282 'text/html; charset=utf-8; xxx="yyy"'); |
283 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 283 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
284 contentType = new _ContentType.fromString( | 284 contentType = new _ContentType.fromString( |
285 " text/html ; charset = utf-8 ; xxx=yyy "); | 285 " text/html ; charset = utf-8 ; xxx=yyy "); |
286 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 286 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
287 } | 287 } |
288 | 288 |
289 void testContentTypeCache() { | 289 void testContentTypeCache() { |
290 _HttpHeaders headers = new _HttpHeaders(); | 290 _HttpHeaders headers = new _HttpHeaders("1.1"); |
291 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); | 291 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); |
292 Expect.equals("text", headers.contentType.primaryType); | 292 Expect.equals("text", headers.contentType.primaryType); |
293 Expect.equals("html", headers.contentType.subType); | 293 Expect.equals("html", headers.contentType.subType); |
294 Expect.equals("text/html", headers.contentType.value); | 294 Expect.equals("text/html", headers.contentType.value); |
295 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); | 295 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); |
296 Expect.equals("text", headers.contentType.primaryType); | 296 Expect.equals("text", headers.contentType.primaryType); |
297 Expect.equals("plain", headers.contentType.subType); | 297 Expect.equals("plain", headers.contentType.subType); |
298 Expect.equals("text/plain", headers.contentType.value); | 298 Expect.equals("text/plain", headers.contentType.value); |
299 headers.removeAll(HttpHeaders.CONTENT_TYPE); | 299 headers.removeAll(HttpHeaders.CONTENT_TYPE); |
300 Expect.equals("", headers.contentType.primaryType); | 300 Expect.equals("", headers.contentType.primaryType); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 testIfModifiedSince(); | 404 testIfModifiedSince(); |
405 testHost(); | 405 testHost(); |
406 testEnumeration(); | 406 testEnumeration(); |
407 testHeaderValue(); | 407 testHeaderValue(); |
408 testContentType(); | 408 testContentType(); |
409 testContentTypeCache(); | 409 testContentTypeCache(); |
410 testCookie(); | 410 testCookie(); |
411 testInvalidCookie(); | 411 testInvalidCookie(); |
412 testHeaderLists(); | 412 testHeaderLists(); |
413 } | 413 } |
OLD | NEW |