| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 if (values != null) { | 516 if (values != null) { |
| 517 values.forEach((headerValue) => parseCookieString(headerValue)); | 517 values.forEach((headerValue) => parseCookieString(headerValue)); |
| 518 } | 518 } |
| 519 return cookies; | 519 return cookies; |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 | 522 |
| 523 | 523 |
| 524 class _HeaderValue implements HeaderValue { | 524 class _HeaderValue implements HeaderValue { |
| 525 String _value; | 525 String _value; |
| 526 _UnmodifiableMap<String, String> _parameters; | 526 Map<String, String> _parameters; |
| 527 Map<String, String> _unmodifiableParameters; |
| 527 | 528 |
| 528 _HeaderValue([String this._value = "", Map<String, String> parameters]) { | 529 _HeaderValue([String this._value = "", Map<String, String> parameters]) { |
| 529 if (parameters != null) { | 530 if (parameters != null) { |
| 530 _parameters = | 531 _parameters = new HashMap<String, String>.from(parameters); |
| 531 new _UnmodifiableMap(new HashMap<String, String>.from(parameters)); | |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 static _HeaderValue parse(String value, | 535 static _HeaderValue parse(String value, |
| 536 {parameterSeparator: ";", | 536 {parameterSeparator: ";", |
| 537 preserveBackslash: false}) { | 537 preserveBackslash: false}) { |
| 538 // Parse the string. | 538 // Parse the string. |
| 539 var result = new _HeaderValue(); | 539 var result = new _HeaderValue(); |
| 540 result._parse(value, parameterSeparator, preserveBackslash); | 540 result._parse(value, parameterSeparator, preserveBackslash); |
| 541 return result; | 541 return result; |
| 542 } | 542 } |
| 543 | 543 |
| 544 String get value => _value; | 544 String get value => _value; |
| 545 | 545 |
| 546 void _ensureParameters() { | 546 void _ensureParameters() { |
| 547 if (_parameters == null) { | 547 if (_parameters == null) { |
| 548 _parameters = new _UnmodifiableMap(new HashMap<String, String>()); | 548 _parameters = new HashMap<String, String>(); |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 | 551 |
| 552 Map<String, String> get parameters { | 552 Map<String, String> get parameters { |
| 553 _ensureParameters(); | 553 _ensureParameters(); |
| 554 return _parameters; | 554 if (_unmodifiableParameters == null) { |
| 555 _unmodifiableParameters = new UnmodifiableMapView(_parameters); |
| 556 } |
| 557 return _unmodifiableParameters; |
| 555 } | 558 } |
| 556 | 559 |
| 557 String toString() { | 560 String toString() { |
| 558 StringBuffer sb = new StringBuffer(); | 561 StringBuffer sb = new StringBuffer(); |
| 559 sb.write(_value); | 562 sb.write(_value); |
| 560 if (parameters != null && parameters.length > 0) { | 563 if (parameters != null && parameters.length > 0) { |
| 561 _parameters.forEach((String name, String value) { | 564 _parameters.forEach((String name, String value) { |
| 562 sb..write("; ")..write(name)..write("=")..write(value); | 565 sb..write("; ")..write(name)..write("=")..write(value); |
| 563 }); | 566 }); |
| 564 } | 567 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 594 } | 597 } |
| 595 index++; | 598 index++; |
| 596 } | 599 } |
| 597 | 600 |
| 598 void maybeExpect(String expected) { | 601 void maybeExpect(String expected) { |
| 599 if (s[index] == expected) index++; | 602 if (s[index] == expected) index++; |
| 600 } | 603 } |
| 601 | 604 |
| 602 void parseParameters() { | 605 void parseParameters() { |
| 603 var parameters = new HashMap<String, String>(); | 606 var parameters = new HashMap<String, String>(); |
| 604 _parameters = new _UnmodifiableMap(parameters); | 607 _parameters = new UnmodifiableMapView(parameters); |
| 605 | 608 |
| 606 String parseParameterName() { | 609 String parseParameterName() { |
| 607 int start = index; | 610 int start = index; |
| 608 while (!done()) { | 611 while (!done()) { |
| 609 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; | 612 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; |
| 610 index++; | 613 index++; |
| 611 } | 614 } |
| 612 return s.substring(start, index).toLowerCase(); | 615 return s.substring(start, index).toLowerCase(); |
| 613 } | 616 } |
| 614 | 617 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 String subType, | 676 String subType, |
| 674 String charset, | 677 String charset, |
| 675 Map<String, String> parameters) | 678 Map<String, String> parameters) |
| 676 : _primaryType = primaryType, _subType = subType, super("") { | 679 : _primaryType = primaryType, _subType = subType, super("") { |
| 677 if (_primaryType == null) _primaryType = ""; | 680 if (_primaryType == null) _primaryType = ""; |
| 678 if (_subType == null) _subType = ""; | 681 if (_subType == null) _subType = ""; |
| 679 _value = "$_primaryType/$_subType"; | 682 _value = "$_primaryType/$_subType"; |
| 680 if (parameters != null) { | 683 if (parameters != null) { |
| 681 _ensureParameters(); | 684 _ensureParameters(); |
| 682 parameters.forEach((String key, String value) { | 685 parameters.forEach((String key, String value) { |
| 683 this._parameters._map[key.toLowerCase()] = value.toLowerCase(); | 686 this._parameters[key.toLowerCase()] = value.toLowerCase(); |
| 684 }); | 687 }); |
| 685 } | 688 } |
| 686 if (charset != null) { | 689 if (charset != null) { |
| 687 _ensureParameters(); | 690 _ensureParameters(); |
| 688 this._parameters._map["charset"] = charset.toLowerCase(); | 691 this._parameters["charset"] = charset.toLowerCase(); |
| 689 } | 692 } |
| 690 } | 693 } |
| 691 | 694 |
| 692 _ContentType._(); | 695 _ContentType._(); |
| 693 | 696 |
| 694 static _ContentType parse(String value) { | 697 static _ContentType parse(String value) { |
| 695 var result = new _ContentType._(); | 698 var result = new _ContentType._(); |
| 696 result._parse(value, ";", false); | 699 result._parse(value, ";", false); |
| 697 int index = result._value.indexOf("/"); | 700 int index = result._value.indexOf("/"); |
| 698 if (index == -1 || index == (result._value.length - 1)) { | 701 if (index == -1 || index == (result._value.length - 1)) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 (codeUnit >= 0x23 && codeUnit <= 0x2B) || | 864 (codeUnit >= 0x23 && codeUnit <= 0x2B) || |
| 862 (codeUnit >= 0x2D && codeUnit <= 0x3A) || | 865 (codeUnit >= 0x2D && codeUnit <= 0x3A) || |
| 863 (codeUnit >= 0x3C && codeUnit <= 0x5B) || | 866 (codeUnit >= 0x3C && codeUnit <= 0x5B) || |
| 864 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { | 867 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { |
| 865 throw new FormatException( | 868 throw new FormatException( |
| 866 "Invalid character in cookie value, code unit: '$codeUnit'"); | 869 "Invalid character in cookie value, code unit: '$codeUnit'"); |
| 867 } | 870 } |
| 868 } | 871 } |
| 869 } | 872 } |
| 870 } | 873 } |
| 871 | |
| 872 | |
| 873 class _UnmodifiableMap<K, V> implements Map<K, V> { | |
| 874 final Map _map; | |
| 875 const _UnmodifiableMap(this._map); | |
| 876 | |
| 877 bool containsValue(Object value) => _map.containsValue(value); | |
| 878 bool containsKey(Object key) => _map.containsKey(key); | |
| 879 V operator [](Object key) => _map[key]; | |
| 880 void operator []=(K key, V value) { | |
| 881 throw new UnsupportedError("Cannot modify an unmodifiable map"); | |
| 882 } | |
| 883 V putIfAbsent(K key, V ifAbsent()) { | |
| 884 throw new UnsupportedError("Cannot modify an unmodifiable map"); | |
| 885 } | |
| 886 addAll(Map other) { | |
| 887 throw new UnsupportedError("Cannot modify an unmodifiable map"); | |
| 888 } | |
| 889 V remove(Object key) { | |
| 890 throw new UnsupportedError("Cannot modify an unmodifiable map"); | |
| 891 } | |
| 892 void clear() { | |
| 893 throw new UnsupportedError("Cannot modify an unmodifiable map"); | |
| 894 } | |
| 895 void forEach(void f(K key, V value)) => _map.forEach(f); | |
| 896 Iterable<K> get keys => _map.keys; | |
| 897 Iterable<V> get values => _map.values; | |
| 898 int get length => _map.length; | |
| 899 bool get isEmpty => _map.isEmpty; | |
| 900 bool get isNotEmpty => _map.isNotEmpty; | |
| 901 } | |
| OLD | NEW |