Chromium Code Reviews| 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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 List<String> values = _headers[name]; | 34 List<String> values = _headers[name]; |
| 35 if (values == null) return null; | 35 if (values == null) return null; |
| 36 if (values.length > 1) { | 36 if (values.length > 1) { |
| 37 throw new HttpException("More than one value for header $name"); | 37 throw new HttpException("More than one value for header $name"); |
| 38 } | 38 } |
| 39 return values[0]; | 39 return values[0]; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void add(String name, value) { | 42 void add(String name, value) { |
| 43 _checkMutable(); | 43 _checkMutable(); |
| 44 var lowerCaseName = name.toLowerCase(); | 44 _addAll(name.toLowerCase(), value); |
| 45 } | |
| 46 | |
| 47 void _addAll(String name, value) { | |
| 45 if (value is List) { | 48 if (value is List) { |
| 46 for (int i = 0; i < value.length; i++) { | 49 for (int i = 0; i < value.length; i++) { |
| 47 _add(lowerCaseName, value[i]); | 50 _add(name, value[i]); |
| 48 } | 51 } |
| 49 } else { | 52 } else { |
| 50 _add(lowerCaseName, value); | 53 _add(name, value); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 | 56 |
| 54 void set(String name, Object value) { | 57 void set(String name, Object value) { |
| 58 _checkMutable(); | |
| 55 name = name.toLowerCase(); | 59 name = name.toLowerCase(); |
| 56 _checkMutable(); | 60 _headers.remove(name); |
| 57 removeAll(name); | 61 _addAll(name, value); |
| 58 add(name, value); | |
| 59 } | 62 } |
| 60 | 63 |
| 61 void remove(String name, Object value) { | 64 void remove(String name, Object value) { |
| 62 _checkMutable(); | 65 _checkMutable(); |
| 63 name = name.toLowerCase(); | 66 name = name.toLowerCase(); |
| 64 List<String> values = _headers[name]; | 67 List<String> values = _headers[name]; |
| 65 if (values != null) { | 68 if (values != null) { |
| 66 int index = values.indexOf(value); | 69 int index = values.indexOf(value); |
| 67 if (index != -1) { | 70 if (index != -1) { |
| 68 values.removeRange(index, index + 1); | 71 values.removeRange(index, index + 1); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 if (protocolVersion == "1.0" && | 122 if (protocolVersion == "1.0" && |
| 120 persistentConnection && | 123 persistentConnection && |
| 121 contentLength == -1) { | 124 contentLength == -1) { |
| 122 throw new HttpException( | 125 throw new HttpException( |
| 123 "Trying to clear ContentLength on HTTP 1.0 headers with " | 126 "Trying to clear ContentLength on HTTP 1.0 headers with " |
| 124 "'Connection: Keep-Alive' set"); | 127 "'Connection: Keep-Alive' set"); |
| 125 } | 128 } |
| 126 if (_contentLength == contentLength) return; | 129 if (_contentLength == contentLength) return; |
| 127 _contentLength = contentLength; | 130 _contentLength = contentLength; |
| 128 if (_contentLength >= 0) { | 131 if (_contentLength >= 0) { |
| 129 if (chunkedTransferEncoding) chunkedTransferEncoding = false; | 132 if (chunkedTransferEncoding) chunkedTransferEncoding = false; |
|
Søren Gjesse
2013/11/21 13:03:03
Accidental edit?
Anders Johnsen
2013/11/21 13:14:41
Done.
| |
| 133 | |
| 130 _set(HttpHeaders.CONTENT_LENGTH, contentLength.toString()); | 134 _set(HttpHeaders.CONTENT_LENGTH, contentLength.toString()); |
| 131 } else { | 135 } else { |
| 132 removeAll(HttpHeaders.CONTENT_LENGTH); | 136 removeAll(HttpHeaders.CONTENT_LENGTH); |
| 133 if (protocolVersion == "1.1") { | 137 if (protocolVersion == "1.1") { |
| 134 chunkedTransferEncoding = true; | 138 chunkedTransferEncoding = true; |
| 135 } | 139 } |
| 136 } | 140 } |
| 137 } | 141 } |
| 138 | 142 |
| 139 bool get chunkedTransferEncoding => _chunkedTransferEncoding; | 143 bool get chunkedTransferEncoding => _chunkedTransferEncoding; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 _headers[name] = values; | 339 _headers[name] = values; |
| 336 } | 340 } |
| 337 if (value is DateTime) { | 341 if (value is DateTime) { |
| 338 values.add(HttpDate.format(value)); | 342 values.add(HttpDate.format(value)); |
| 339 } else { | 343 } else { |
| 340 values.add(value.toString()); | 344 values.add(value.toString()); |
| 341 } | 345 } |
| 342 } | 346 } |
| 343 | 347 |
| 344 void _set(String name, String value) { | 348 void _set(String name, String value) { |
| 345 name = name.toLowerCase(); | 349 assert(name == name.toLowerCase()); |
| 346 List<String> values = new List<String>(); | 350 List<String> values = new List<String>(); |
| 347 _headers[name] = values; | 351 _headers[name] = values; |
| 348 values.add(value); | 352 values.add(value); |
| 349 } | 353 } |
| 350 | 354 |
| 351 _checkMutable() { | 355 _checkMutable() { |
| 352 if (!_mutable) throw new HttpException("HTTP headers are not mutable"); | 356 if (!_mutable) throw new HttpException("HTTP headers are not mutable"); |
| 353 } | 357 } |
| 354 | 358 |
| 355 _updateHostHeader() { | 359 _updateHostHeader() { |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 void clear() { | 847 void clear() { |
| 844 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 848 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 845 } | 849 } |
| 846 void forEach(void f(K key, V value)) => _map.forEach(f); | 850 void forEach(void f(K key, V value)) => _map.forEach(f); |
| 847 Iterable<K> get keys => _map.keys; | 851 Iterable<K> get keys => _map.keys; |
| 848 Iterable<V> get values => _map.values; | 852 Iterable<V> get values => _map.values; |
| 849 int get length => _map.length; | 853 int get length => _map.length; |
| 850 bool get isEmpty => _map.isEmpty; | 854 bool get isEmpty => _map.isEmpty; |
| 851 bool get isNotEmpty => _map.isNotEmpty; | 855 bool get isNotEmpty => _map.isNotEmpty; |
| 852 } | 856 } |
| OLD | NEW |