| 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 _HttpHeaders(this.protocolVersion) | 20 final int _defaultPortForScheme; |
| 21 : _headers = new HashMap<String, List<String>>() { | 21 |
| 22 _HttpHeaders(this.protocolVersion, |
| 23 {int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT}) |
| 24 : _headers = new HashMap<String, List<String>>(), |
| 25 _defaultPortForScheme = defaultPortForScheme { |
| 22 if (protocolVersion == "1.0") { | 26 if (protocolVersion == "1.0") { |
| 23 _persistentConnection = false; | 27 _persistentConnection = false; |
| 24 } | 28 } |
| 25 } | 29 } |
| 26 | 30 |
| 27 List<String> operator[](String name) => _headers[name.toLowerCase()]; | 31 List<String> operator[](String name) => _headers[name.toLowerCase()]; |
| 28 | 32 |
| 29 String value(String name) { | 33 String value(String name) { |
| 30 name = name.toLowerCase(); | 34 name = name.toLowerCase(); |
| 31 List<String> values = _headers[name]; | 35 List<String> values = _headers[name]; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 List<String> values = new List<String>(); | 365 List<String> values = new List<String>(); |
| 362 _headers[name] = values; | 366 _headers[name] = values; |
| 363 values.add(value); | 367 values.add(value); |
| 364 } | 368 } |
| 365 | 369 |
| 366 _checkMutable() { | 370 _checkMutable() { |
| 367 if (!_mutable) throw new HttpException("HTTP headers are not mutable"); | 371 if (!_mutable) throw new HttpException("HTTP headers are not mutable"); |
| 368 } | 372 } |
| 369 | 373 |
| 370 _updateHostHeader() { | 374 _updateHostHeader() { |
| 371 bool defaultPort = _port == null || _port == HttpClient.DEFAULT_HTTP_PORT; | 375 bool defaultPort = _port == null || _port == _defaultPortForScheme; |
| 372 String portPart = defaultPort ? "" : ":$_port"; | 376 String portPart = defaultPort ? "" : ":$_port"; |
| 373 _set("host", "$host$portPart"); | 377 _set("host", "$host$portPart"); |
| 374 } | 378 } |
| 375 | 379 |
| 376 _foldHeader(String name) { | 380 _foldHeader(String name) { |
| 377 if (name == HttpHeaders.SET_COOKIE || | 381 if (name == HttpHeaders.SET_COOKIE || |
| 378 (_noFoldingHeaders != null && | 382 (_noFoldingHeaders != null && |
| 379 _noFoldingHeaders.indexOf(name) != -1)) { | 383 _noFoldingHeaders.indexOf(name) != -1)) { |
| 380 return false; | 384 return false; |
| 381 } | 385 } |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 void clear() { | 892 void clear() { |
| 889 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 893 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 890 } | 894 } |
| 891 void forEach(void f(K key, V value)) => _map.forEach(f); | 895 void forEach(void f(K key, V value)) => _map.forEach(f); |
| 892 Iterable<K> get keys => _map.keys; | 896 Iterable<K> get keys => _map.keys; |
| 893 Iterable<V> get values => _map.values; | 897 Iterable<V> get values => _map.values; |
| 894 int get length => _map.length; | 898 int get length => _map.length; |
| 895 bool get isEmpty => _map.isEmpty; | 899 bool get isEmpty => _map.isEmpty; |
| 896 bool get isNotEmpty => _map.isNotEmpty; | 900 bool get isNotEmpty => _map.isNotEmpty; |
| 897 } | 901 } |
| OLD | NEW |