OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _HttpHeaders implements HttpHeaders { | 7 class _HttpHeaders implements HttpHeaders { |
8 final Map<String, List<String>> _headers; | 8 final Map<String, List<String>> _headers; |
9 final String protocolVersion; | 9 final String protocolVersion; |
10 | 10 |
11 bool _mutable = true; // Are the headers currently mutable? | 11 bool _mutable = true; // Are the headers currently mutable? |
12 List<String> _noFoldingHeaders; | 12 List<String> _noFoldingHeaders; |
13 | 13 |
14 int _contentLength = -1; | 14 int _contentLength = -1; |
15 bool _persistentConnection = true; | 15 bool _persistentConnection = true; |
16 bool _chunkedTransferEncoding = false; | 16 bool _chunkedTransferEncoding = false; |
17 String _host; | 17 String _host; |
18 int _port; | 18 int _port; |
19 | 19 |
20 final int _defaultPortForScheme; | 20 final int _defaultPortForScheme; |
21 | 21 |
22 _HttpHeaders(this.protocolVersion, | 22 _HttpHeaders(this.protocolVersion, |
23 {int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT}) | 23 {int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT, |
24 _HttpHeaders initialHeaders}) | |
24 : _headers = new HashMap<String, List<String>>(), | 25 : _headers = new HashMap<String, List<String>>(), |
25 _defaultPortForScheme = defaultPortForScheme { | 26 _defaultPortForScheme = defaultPortForScheme { |
27 if (initialHeaders != null) { | |
28 initialHeaders._headers.forEach((name, value) => _headers[name] = value); | |
29 _contentLength = initialHeaders._contentLength; | |
30 _persistentConnection = initialHeaders._persistentConnection; | |
31 _chunkedTransferEncoding = initialHeaders._chunkedTransferEncoding; | |
Anders Johnsen
2014/08/12 05:49:13
This may be problematic if protocolVersions doesn'
Søren Gjesse
2014/08/12 06:53:49
Good point. Clearing it for 1.0. Anyway setting ch
| |
32 _host = initialHeaders._host; | |
33 _port = initialHeaders._port; | |
34 } | |
26 if (protocolVersion == "1.0") { | 35 if (protocolVersion == "1.0") { |
27 _persistentConnection = false; | 36 _persistentConnection = false; |
28 } | 37 } |
29 } | 38 } |
30 | 39 |
31 List<String> operator[](String name) => _headers[name.toLowerCase()]; | 40 List<String> operator[](String name) => _headers[name.toLowerCase()]; |
32 | 41 |
33 String value(String name) { | 42 String value(String name) { |
34 name = name.toLowerCase(); | 43 name = name.toLowerCase(); |
35 List<String> values = _headers[name]; | 44 List<String> values = _headers[name]; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 } else { | 254 } else { |
246 return null; | 255 return null; |
247 } | 256 } |
248 } | 257 } |
249 | 258 |
250 void set contentType(ContentType contentType) { | 259 void set contentType(ContentType contentType) { |
251 _checkMutable(); | 260 _checkMutable(); |
252 _set(HttpHeaders.CONTENT_TYPE, contentType.toString()); | 261 _set(HttpHeaders.CONTENT_TYPE, contentType.toString()); |
253 } | 262 } |
254 | 263 |
264 void clear() { | |
265 _checkMutable(); | |
266 _headers.clear(); | |
267 _contentLength = -1; | |
268 _persistentConnection = true; | |
269 _chunkedTransferEncoding = false; | |
270 _host = null; | |
271 _port = null; | |
272 } | |
273 | |
255 // [name] must be a lower-case version of the name. | 274 // [name] must be a lower-case version of the name. |
256 void _add(String name, value) { | 275 void _add(String name, value) { |
257 assert(name == _validateField(name)); | 276 assert(name == _validateField(name)); |
258 // Use the length as index on what method to call. This is notable | 277 // Use the length as index on what method to call. This is notable |
259 // faster than computing hash and looking up in a hash-map. | 278 // faster than computing hash and looking up in a hash-map. |
260 switch (name.length) { | 279 switch (name.length) { |
261 case 4: | 280 case 4: |
262 if (HttpHeaders.DATE == name) { | 281 if (HttpHeaders.DATE == name) { |
263 _addDate(name, value); | 282 _addDate(name, value); |
264 return; | 283 return; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 String name; | 813 String name; |
795 String value; | 814 String value; |
796 DateTime expires; | 815 DateTime expires; |
797 int maxAge; | 816 int maxAge; |
798 String domain; | 817 String domain; |
799 String path; | 818 String path; |
800 bool httpOnly = false; | 819 bool httpOnly = false; |
801 bool secure = false; | 820 bool secure = false; |
802 | 821 |
803 _Cookie([this.name, this.value]) { | 822 _Cookie([this.name, this.value]) { |
823 // Default value of httponly is true. | |
824 httpOnly = true; | |
804 _validate(); | 825 _validate(); |
805 } | 826 } |
806 | 827 |
807 _Cookie.fromSetCookieValue(String value) { | 828 _Cookie.fromSetCookieValue(String value) { |
808 // Parse the 'set-cookie' header value. | 829 // Parse the 'set-cookie' header value. |
809 _parseSetCookieValue(value); | 830 _parseSetCookieValue(value); |
810 } | 831 } |
811 | 832 |
812 // Parse a 'set-cookie' header value according to the rules in RFC 6265. | 833 // Parse a 'set-cookie' header value according to the rules in RFC 6265. |
813 void _parseSetCookieValue(String s) { | 834 void _parseSetCookieValue(String s) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 (codeUnit >= 0x23 && codeUnit <= 0x2B) || | 956 (codeUnit >= 0x23 && codeUnit <= 0x2B) || |
936 (codeUnit >= 0x2D && codeUnit <= 0x3A) || | 957 (codeUnit >= 0x2D && codeUnit <= 0x3A) || |
937 (codeUnit >= 0x3C && codeUnit <= 0x5B) || | 958 (codeUnit >= 0x3C && codeUnit <= 0x5B) || |
938 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { | 959 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { |
939 throw new FormatException( | 960 throw new FormatException( |
940 "Invalid character in cookie value, code unit: '$codeUnit'"); | 961 "Invalid character in cookie value, code unit: '$codeUnit'"); |
941 } | 962 } |
942 } | 963 } |
943 } | 964 } |
944 } | 965 } |
OLD | NEW |