| 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 _HttpHeaders(String this.protocolVersion) | 8 _HttpHeaders(String this.protocolVersion) |
| 9 : _headers = new Map<String, List<String>>(); | 9 : _headers = new Map<String, List<String>>(); |
| 10 | 10 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void set expires(DateTime expires) { | 189 void set expires(DateTime expires) { |
| 190 _checkMutable(); | 190 _checkMutable(); |
| 191 // Format "Expires" header with date in Greenwich Mean Time (GMT). | 191 // Format "Expires" header with date in Greenwich Mean Time (GMT). |
| 192 String formatted = _HttpUtils.formatDate(expires.toUtc()); | 192 String formatted = _HttpUtils.formatDate(expires.toUtc()); |
| 193 _set(HttpHeaders.EXPIRES, formatted); | 193 _set(HttpHeaders.EXPIRES, formatted); |
| 194 } | 194 } |
| 195 | 195 |
| 196 ContentType get contentType { | 196 ContentType get contentType { |
| 197 var values = _headers["content-type"]; | 197 var values = _headers["content-type"]; |
| 198 if (values != null) { | 198 if (values != null) { |
| 199 return new ContentType.fromString(values[0]); | 199 return ContentType.parse(values[0]); |
| 200 } else { | 200 } else { |
| 201 return null; | 201 return null; |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 void set contentType(ContentType contentType) { | 205 void set contentType(ContentType contentType) { |
| 206 _checkMutable(); | 206 _checkMutable(); |
| 207 _set(HttpHeaders.CONTENT_TYPE, contentType.toString()); | 207 _set(HttpHeaders.CONTENT_TYPE, contentType.toString()); |
| 208 } | 208 } |
| 209 | 209 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 int _port; | 470 int _port; |
| 471 } | 471 } |
| 472 | 472 |
| 473 | 473 |
| 474 class _HeaderValue implements HeaderValue { | 474 class _HeaderValue implements HeaderValue { |
| 475 String _value; | 475 String _value; |
| 476 Map<String, String> _parameters; | 476 Map<String, String> _parameters; |
| 477 | 477 |
| 478 _HeaderValue([String this._value = "", this._parameters]); | 478 _HeaderValue([String this._value = "", this._parameters]); |
| 479 | 479 |
| 480 _HeaderValue.fromString(String value, {parameterSeparator: ";"}) { | 480 static _HeaderValue parse(String value, {parameterSeparator: ";"}) { |
| 481 // Parse the string. | 481 // Parse the string. |
| 482 _parse(value, parameterSeparator); | 482 var result = new _HeaderValue(); |
| 483 result._parse(value, parameterSeparator); |
| 484 return result; |
| 483 } | 485 } |
| 484 | 486 |
| 485 String get value => _value; | 487 String get value => _value; |
| 486 | 488 |
| 487 Map<String, String> get parameters { | 489 Map<String, String> get parameters { |
| 488 if (_parameters == null) _parameters = new Map<String, String>(); | 490 if (_parameters == null) _parameters = new Map<String, String>(); |
| 489 return _parameters; | 491 return _parameters; |
| 490 } | 492 } |
| 491 | 493 |
| 492 String toString() { | 494 String toString() { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 if (parameters != null) { | 616 if (parameters != null) { |
| 615 parameters.forEach((String key, String value) { | 617 parameters.forEach((String key, String value) { |
| 616 this.parameters[key.toLowerCase()] = value.toLowerCase(); | 618 this.parameters[key.toLowerCase()] = value.toLowerCase(); |
| 617 }); | 619 }); |
| 618 } | 620 } |
| 619 if (charset != null) { | 621 if (charset != null) { |
| 620 this.parameters["charset"] = charset.toLowerCase(); | 622 this.parameters["charset"] = charset.toLowerCase(); |
| 621 } | 623 } |
| 622 } | 624 } |
| 623 | 625 |
| 624 _ContentType.fromString(String value) : super.fromString(value) { | 626 _ContentType._(); |
| 625 int index = _value.indexOf("/"); | 627 |
| 626 if (index == -1 || index == (_value.length - 1)) { | 628 static _ContentType parse(String value) { |
| 627 _primaryType = _value.trim().toLowerCase(); | 629 var result = new _ContentType._(); |
| 628 _subType = ""; | 630 result._parse(value, ";"); |
| 631 int index = result._value.indexOf("/"); |
| 632 if (index == -1 || index == (result._value.length - 1)) { |
| 633 result._primaryType = result._value.trim().toLowerCase(); |
| 634 result._subType = ""; |
| 629 } else { | 635 } else { |
| 630 _primaryType = _value.substring(0, index).trim().toLowerCase(); | 636 result._primaryType = result._value.substring(0, index).trim().toLowerCase
(); |
| 631 _subType = _value.substring(index + 1).trim().toLowerCase(); | 637 result._subType = result._value.substring(index + 1).trim().toLowerCase(); |
| 632 } | 638 } |
| 639 return result; |
| 633 } | 640 } |
| 634 | 641 |
| 635 String get mimeType => '$primaryType/$subType'; | 642 String get mimeType => '$primaryType/$subType'; |
| 636 | 643 |
| 637 String get primaryType => _primaryType; | 644 String get primaryType => _primaryType; |
| 638 | 645 |
| 639 String get subType => _subType; | 646 String get subType => _subType; |
| 640 | 647 |
| 641 String get charset => parameters["charset"]; | 648 String get charset => parameters["charset"]; |
| 642 } | 649 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 771 |
| 765 String name; | 772 String name; |
| 766 String value; | 773 String value; |
| 767 DateTime expires; | 774 DateTime expires; |
| 768 int maxAge; | 775 int maxAge; |
| 769 String domain; | 776 String domain; |
| 770 String path; | 777 String path; |
| 771 bool httpOnly = false; | 778 bool httpOnly = false; |
| 772 bool secure = false; | 779 bool secure = false; |
| 773 } | 780 } |
| OLD | NEW |