| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 String _value; | 475 String _value; |
| 476 _UnmodifiableMap<String, String> _parameters; | 476 _UnmodifiableMap<String, String> _parameters; |
| 477 | 477 |
| 478 _HeaderValue([String this._value = "", Map<String, String> parameters]) { | 478 _HeaderValue([String this._value = "", Map<String, String> parameters]) { |
| 479 if (parameters != null) { | 479 if (parameters != null) { |
| 480 _parameters = | 480 _parameters = |
| 481 new _UnmodifiableMap(new Map<String, String>.from(parameters)); | 481 new _UnmodifiableMap(new Map<String, String>.from(parameters)); |
| 482 } | 482 } |
| 483 } | 483 } |
| 484 | 484 |
| 485 static _HeaderValue parse(String value, {parameterSeparator: ";"}) { | 485 static _HeaderValue parse(String value, |
| 486 {parameterSeparator: ";", |
| 487 preserveBackslash: false}) { |
| 486 // Parse the string. | 488 // Parse the string. |
| 487 var result = new _HeaderValue(); | 489 var result = new _HeaderValue(); |
| 488 result._parse(value, parameterSeparator); | 490 result._parse(value, parameterSeparator, preserveBackslash); |
| 489 return result; | 491 return result; |
| 490 } | 492 } |
| 491 | 493 |
| 492 String get value => _value; | 494 String get value => _value; |
| 493 | 495 |
| 494 void _ensureParameters() { | 496 void _ensureParameters() { |
| 495 if (_parameters == null) { | 497 if (_parameters == null) { |
| 496 _parameters = new _UnmodifiableMap(new Map<String, String>()); | 498 _parameters = new _UnmodifiableMap(new Map<String, String>()); |
| 497 } | 499 } |
| 498 } | 500 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 509 _parameters.forEach((String name, String value) { | 511 _parameters.forEach((String name, String value) { |
| 510 sb.write("; "); | 512 sb.write("; "); |
| 511 sb.write(name); | 513 sb.write(name); |
| 512 sb.write("="); | 514 sb.write("="); |
| 513 sb.write(value); | 515 sb.write(value); |
| 514 }); | 516 }); |
| 515 } | 517 } |
| 516 return sb.toString(); | 518 return sb.toString(); |
| 517 } | 519 } |
| 518 | 520 |
| 519 void _parse(String s, String parameterSeparator) { | 521 void _parse(String s, String parameterSeparator, bool preserveBackslash) { |
| 520 int index = 0; | 522 int index = 0; |
| 521 | 523 |
| 522 bool done() => index == s.length; | 524 bool done() => index == s.length; |
| 523 | 525 |
| 524 void skipWS() { | 526 void skipWS() { |
| 525 while (!done()) { | 527 while (!done()) { |
| 526 if (s[index] != " " && s[index] != "\t") return; | 528 if (s[index] != " " && s[index] != "\t") return; |
| 527 index++; | 529 index++; |
| 528 } | 530 } |
| 529 } | 531 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } | 564 } |
| 563 return s.substring(start, index).toLowerCase(); | 565 return s.substring(start, index).toLowerCase(); |
| 564 } | 566 } |
| 565 | 567 |
| 566 String parseParameterValue() { | 568 String parseParameterValue() { |
| 567 if (s[index] == "\"") { | 569 if (s[index] == "\"") { |
| 568 // Parse quoted value. | 570 // Parse quoted value. |
| 569 StringBuffer sb = new StringBuffer(); | 571 StringBuffer sb = new StringBuffer(); |
| 570 index++; | 572 index++; |
| 571 while (!done()) { | 573 while (!done()) { |
| 574 print(s[index]); |
| 572 if (s[index] == "\\") { | 575 if (s[index] == "\\") { |
| 573 if (index + 1 == s.length) { | 576 if (index + 1 == s.length) { |
| 574 throw new HttpException("Failed to parse header value"); | 577 throw new HttpException("Failed to parse header value"); |
| 575 } | 578 } |
| 579 if (preserveBackslash && s[index + 1] != "\"") { |
| 580 sb.write(s[index]); |
| 581 } |
| 576 index++; | 582 index++; |
| 577 } else if (s[index] == "\"") { | 583 } else if (s[index] == "\"") { |
| 578 index++; | 584 index++; |
| 579 break; | 585 break; |
| 580 } | 586 } |
| 581 sb.write(s[index]); | 587 sb.write(s[index]); |
| 582 index++; | 588 index++; |
| 583 } | 589 } |
| 584 return sb.toString(); | 590 return sb.toString(); |
| 585 } else { | 591 } else { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 if (charset != null) { | 640 if (charset != null) { |
| 635 _ensureParameters(); | 641 _ensureParameters(); |
| 636 this._parameters._map["charset"] = charset.toLowerCase(); | 642 this._parameters._map["charset"] = charset.toLowerCase(); |
| 637 } | 643 } |
| 638 } | 644 } |
| 639 | 645 |
| 640 _ContentType._(); | 646 _ContentType._(); |
| 641 | 647 |
| 642 static _ContentType parse(String value) { | 648 static _ContentType parse(String value) { |
| 643 var result = new _ContentType._(); | 649 var result = new _ContentType._(); |
| 644 result._parse(value, ";"); | 650 result._parse(value, ";", false); |
| 645 int index = result._value.indexOf("/"); | 651 int index = result._value.indexOf("/"); |
| 646 if (index == -1 || index == (result._value.length - 1)) { | 652 if (index == -1 || index == (result._value.length - 1)) { |
| 647 result._primaryType = result._value.trim().toLowerCase(); | 653 result._primaryType = result._value.trim().toLowerCase(); |
| 648 result._subType = ""; | 654 result._subType = ""; |
| 649 } else { | 655 } else { |
| 650 result._primaryType = | 656 result._primaryType = |
| 651 result._value.substring(0, index).trim().toLowerCase(); | 657 result._value.substring(0, index).trim().toLowerCase(); |
| 652 result._subType = result._value.substring(index + 1).trim().toLowerCase(); | 658 result._subType = result._value.substring(index + 1).trim().toLowerCase(); |
| 653 } | 659 } |
| 654 return result; | 660 return result; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 void clear() { | 823 void clear() { |
| 818 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 824 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 819 } | 825 } |
| 820 void forEach(void f(K key, V value)) => _map.forEach(f); | 826 void forEach(void f(K key, V value)) => _map.forEach(f); |
| 821 Iterable<K> get keys => _map.keys; | 827 Iterable<K> get keys => _map.keys; |
| 822 Iterable<V> get values => _map.values; | 828 Iterable<V> get values => _map.values; |
| 823 int get length => _map.length; | 829 int get length => _map.length; |
| 824 bool get isEmpty => _map.isEmpty; | 830 bool get isEmpty => _map.isEmpty; |
| 825 bool get isNotEmpty => _map.isNotEmpty; | 831 bool get isNotEmpty => _map.isNotEmpty; |
| 826 } | 832 } |
| OLD | NEW |