| 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 class _HttpHeaders implements HttpHeaders { | 5 class _HttpHeaders implements HttpHeaders { |
| 6 _HttpHeaders() : _headers = new Map<String, List<String>>(); | 6 _HttpHeaders() : _headers = new Map<String, List<String>>(); |
| 7 | 7 |
| 8 List<String> operator[](String name) { | 8 List<String> operator[](String name) { |
| 9 name = name.toLowerCase(); | 9 name = name.toLowerCase(); |
| 10 return _headers[name]; | 10 return _headers[name]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 void forEach(void f(String name, List<String> values)) { | 59 void forEach(void f(String name, List<String> values)) { |
| 60 _headers.forEach(f); | 60 _headers.forEach(f); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void noFolding(String name) { | 63 void noFolding(String name) { |
| 64 if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>(); | 64 if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>(); |
| 65 _noFoldingHeaders.add(name); | 65 _noFoldingHeaders.add(name); |
| 66 } | 66 } |
| 67 | 67 |
| 68 int get contentLength => _contentLength; |
| 69 |
| 70 void set contentLength(int contentLength) { |
| 71 _checkMutable(); |
| 72 _contentLength = contentLength; |
| 73 if (_contentLength >= 0) { |
| 74 _set("content-length", contentLength.toString()); |
| 75 } else { |
| 76 removeAll("content-length"); |
| 77 } |
| 78 } |
| 79 |
| 68 String get host => _host; | 80 String get host => _host; |
| 69 | 81 |
| 70 void set host(String host) { | 82 void set host(String host) { |
| 71 _checkMutable(); | 83 _checkMutable(); |
| 72 _host = host; | 84 _host = host; |
| 73 _updateHostHeader(); | 85 _updateHostHeader(); |
| 74 } | 86 } |
| 75 | 87 |
| 76 int get port => _port; | 88 int get port => _port; |
| 77 | 89 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 160 } |
| 149 | 161 |
| 150 void set contentType(ContentType contentType) { | 162 void set contentType(ContentType contentType) { |
| 151 _checkMutable(); | 163 _checkMutable(); |
| 152 _set("content-type", contentType.toString()); | 164 _set("content-type", contentType.toString()); |
| 153 } | 165 } |
| 154 | 166 |
| 155 void _add(String name, Object value) { | 167 void _add(String name, Object value) { |
| 156 var lowerCaseName = name.toLowerCase(); | 168 var lowerCaseName = name.toLowerCase(); |
| 157 // TODO(sgjesse): Add immutable state throw HttpException is immutable. | 169 // TODO(sgjesse): Add immutable state throw HttpException is immutable. |
| 158 if (lowerCaseName == "date") { | 170 if (lowerCaseName == "content-length") { |
| 171 if (value is int) { |
| 172 contentLength = value; |
| 173 } else if (value is String) { |
| 174 contentLength = parseInt(value); |
| 175 } else { |
| 176 throw new HttpException("Unexpected type for header named $name"); |
| 177 } |
| 178 } else if (lowerCaseName == "date") { |
| 159 if (value is Date) { | 179 if (value is Date) { |
| 160 date = value; | 180 date = value; |
| 161 } else if (value is String) { | 181 } else if (value is String) { |
| 162 _set("date", value); | 182 _set("date", value); |
| 163 } else { | 183 } else { |
| 164 throw new HttpException("Unexpected type for header named $name"); | 184 throw new HttpException("Unexpected type for header named $name"); |
| 165 } | 185 } |
| 166 } else if (lowerCaseName == "expires") { | 186 } else if (lowerCaseName == "expires") { |
| 167 if (value is Date) { | 187 if (value is Date) { |
| 168 expires = value; | 188 expires = value; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 336 } |
| 317 sb.add("\n"); | 337 sb.add("\n"); |
| 318 }); | 338 }); |
| 319 return sb.toString(); | 339 return sb.toString(); |
| 320 } | 340 } |
| 321 | 341 |
| 322 bool _mutable = true; // Are the headers currently mutable? | 342 bool _mutable = true; // Are the headers currently mutable? |
| 323 Map<String, List<String>> _headers; | 343 Map<String, List<String>> _headers; |
| 324 List<String> _noFoldingHeaders; | 344 List<String> _noFoldingHeaders; |
| 325 | 345 |
| 346 int _contentLength = -1; |
| 326 String _host; | 347 String _host; |
| 327 int _port; | 348 int _port; |
| 328 } | 349 } |
| 329 | 350 |
| 330 | 351 |
| 331 class _HeaderValue implements HeaderValue { | 352 class _HeaderValue implements HeaderValue { |
| 332 _HeaderValue([String this.value = ""]); | 353 _HeaderValue([String this.value = ""]); |
| 333 | 354 |
| 334 _HeaderValue.fromString(String value, {this.parameterSeparator: ";"}) { | 355 _HeaderValue.fromString(String value, {this.parameterSeparator: ";"}) { |
| 335 // Parse the string. | 356 // Parse the string. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 640 |
| 620 String name; | 641 String name; |
| 621 String value; | 642 String value; |
| 622 Date expires; | 643 Date expires; |
| 623 int maxAge; | 644 int maxAge; |
| 624 String domain; | 645 String domain; |
| 625 String path; | 646 String path; |
| 626 bool httpOnly = false; | 647 bool httpOnly = false; |
| 627 bool secure = false; | 648 bool secure = false; |
| 628 } | 649 } |
| OLD | NEW |