| 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 Map<String, String> _parameters; | 526 _UnmodifiableMap<String, String> _parameters; |
| 527 Map<String, String> _unmodifiableParameters; | |
| 528 | 527 |
| 529 _HeaderValue([String this._value = "", Map<String, String> parameters]) { | 528 _HeaderValue([String this._value = "", Map<String, String> parameters]) { |
| 530 if (parameters != null) { | 529 if (parameters != null) { |
| 531 _parameters = new HashMap<String, String>.from(parameters); | 530 _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 HashMap<String, String>(); | 548 _parameters = new _UnmodifiableMap(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 if (_unmodifiableParameters == null) { | 554 return _parameters; |
| 555 _unmodifiableParameters = new UnmodifiableMapView(_parameters); | |
| 556 } | |
| 557 return _unmodifiableParameters; | |
| 558 } | 555 } |
| 559 | 556 |
| 560 String toString() { | 557 String toString() { |
| 561 StringBuffer sb = new StringBuffer(); | 558 StringBuffer sb = new StringBuffer(); |
| 562 sb.write(_value); | 559 sb.write(_value); |
| 563 if (parameters != null && parameters.length > 0) { | 560 if (parameters != null && parameters.length > 0) { |
| 564 _parameters.forEach((String name, String value) { | 561 _parameters.forEach((String name, String value) { |
| 565 sb..write("; ")..write(name)..write("=")..write(value); | 562 sb..write("; ")..write(name)..write("=")..write(value); |
| 566 }); | 563 }); |
| 567 } | 564 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 597 } | 594 } |
| 598 index++; | 595 index++; |
| 599 } | 596 } |
| 600 | 597 |
| 601 void maybeExpect(String expected) { | 598 void maybeExpect(String expected) { |
| 602 if (s[index] == expected) index++; | 599 if (s[index] == expected) index++; |
| 603 } | 600 } |
| 604 | 601 |
| 605 void parseParameters() { | 602 void parseParameters() { |
| 606 var parameters = new HashMap<String, String>(); | 603 var parameters = new HashMap<String, String>(); |
| 607 _parameters = new UnmodifiableMapView(parameters); | 604 _parameters = new _UnmodifiableMap(parameters); |
| 608 | 605 |
| 609 String parseParameterName() { | 606 String parseParameterName() { |
| 610 int start = index; | 607 int start = index; |
| 611 while (!done()) { | 608 while (!done()) { |
| 612 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; | 609 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; |
| 613 index++; | 610 index++; |
| 614 } | 611 } |
| 615 return s.substring(start, index).toLowerCase(); | 612 return s.substring(start, index).toLowerCase(); |
| 616 } | 613 } |
| 617 | 614 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 String subType, | 673 String subType, |
| 677 String charset, | 674 String charset, |
| 678 Map<String, String> parameters) | 675 Map<String, String> parameters) |
| 679 : _primaryType = primaryType, _subType = subType, super("") { | 676 : _primaryType = primaryType, _subType = subType, super("") { |
| 680 if (_primaryType == null) _primaryType = ""; | 677 if (_primaryType == null) _primaryType = ""; |
| 681 if (_subType == null) _subType = ""; | 678 if (_subType == null) _subType = ""; |
| 682 _value = "$_primaryType/$_subType"; | 679 _value = "$_primaryType/$_subType"; |
| 683 if (parameters != null) { | 680 if (parameters != null) { |
| 684 _ensureParameters(); | 681 _ensureParameters(); |
| 685 parameters.forEach((String key, String value) { | 682 parameters.forEach((String key, String value) { |
| 686 this._parameters[key.toLowerCase()] = value.toLowerCase(); | 683 this._parameters._map[key.toLowerCase()] = value.toLowerCase(); |
| 687 }); | 684 }); |
| 688 } | 685 } |
| 689 if (charset != null) { | 686 if (charset != null) { |
| 690 _ensureParameters(); | 687 _ensureParameters(); |
| 691 this._parameters["charset"] = charset.toLowerCase(); | 688 this._parameters._map["charset"] = charset.toLowerCase(); |
| 692 } | 689 } |
| 693 } | 690 } |
| 694 | 691 |
| 695 _ContentType._(); | 692 _ContentType._(); |
| 696 | 693 |
| 697 static _ContentType parse(String value) { | 694 static _ContentType parse(String value) { |
| 698 var result = new _ContentType._(); | 695 var result = new _ContentType._(); |
| 699 result._parse(value, ";", false); | 696 result._parse(value, ";", false); |
| 700 int index = result._value.indexOf("/"); | 697 int index = result._value.indexOf("/"); |
| 701 if (index == -1 || index == (result._value.length - 1)) { | 698 if (index == -1 || index == (result._value.length - 1)) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 (codeUnit >= 0x23 && codeUnit <= 0x2B) || | 861 (codeUnit >= 0x23 && codeUnit <= 0x2B) || |
| 865 (codeUnit >= 0x2D && codeUnit <= 0x3A) || | 862 (codeUnit >= 0x2D && codeUnit <= 0x3A) || |
| 866 (codeUnit >= 0x3C && codeUnit <= 0x5B) || | 863 (codeUnit >= 0x3C && codeUnit <= 0x5B) || |
| 867 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { | 864 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { |
| 868 throw new FormatException( | 865 throw new FormatException( |
| 869 "Invalid character in cookie value, code unit: '$codeUnit'"); | 866 "Invalid character in cookie value, code unit: '$codeUnit'"); |
| 870 } | 867 } |
| 871 } | 868 } |
| 872 } | 869 } |
| 873 } | 870 } |
| 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 |