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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 if (s[index] != " " && s[index] != "\t") return; | 674 if (s[index] != " " && s[index] != "\t") return; |
675 index++; | 675 index++; |
676 } | 676 } |
677 } | 677 } |
678 | 678 |
679 String parseValue() { | 679 String parseValue() { |
680 int start = index; | 680 int start = index; |
681 while (!done()) { | 681 while (!done()) { |
682 if (s[index] == " " || | 682 if (s[index] == " " || |
683 s[index] == "\t" || | 683 s[index] == "\t" || |
| 684 s[index] == "," || |
684 s[index] == parameterSeparator) break; | 685 s[index] == parameterSeparator) break; |
685 index++; | 686 index++; |
686 } | 687 } |
687 return s.substring(start, index); | 688 return s.substring(start, index); |
688 } | 689 } |
689 | 690 |
690 void expect(String expected) { | 691 void expect(String expected) { |
691 if (done() || s[index] != expected) { | 692 if (done() || s[index] != expected) { |
692 throw new HttpException("Failed to parse header value"); | 693 throw new HttpException("Failed to parse header value"); |
693 } | 694 } |
694 index++; | 695 index++; |
695 } | 696 } |
696 | 697 |
697 void maybeExpect(String expected) { | 698 void maybeExpect(String expected) { |
698 if (s[index] == expected) index++; | 699 if (s[index] == expected) index++; |
699 } | 700 } |
700 | 701 |
701 void parseParameters() { | 702 void parseParameters() { |
702 var parameters = new HashMap<String, String>(); | 703 var parameters = new HashMap<String, String>(); |
703 _parameters = new UnmodifiableMapView(parameters); | 704 _parameters = new UnmodifiableMapView(parameters); |
704 | 705 |
705 String parseParameterName() { | 706 String parseParameterName() { |
706 int start = index; | 707 int start = index; |
707 while (!done()) { | 708 while (!done()) { |
708 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; | 709 if (s[index] == " " || |
| 710 s[index] == "\t" || |
| 711 s[index] == "=" || |
| 712 s[index] == ",") break; |
709 index++; | 713 index++; |
710 } | 714 } |
711 return s.substring(start, index).toLowerCase(); | 715 return s.substring(start, index).toLowerCase(); |
712 } | 716 } |
713 | 717 |
714 String parseParameterValue() { | 718 String parseParameterValue() { |
715 if (s[index] == "\"") { | 719 if (s[index] == "\"") { |
716 // Parse quoted value. | 720 // Parse quoted value. |
717 StringBuffer sb = new StringBuffer(); | 721 StringBuffer sb = new StringBuffer(); |
718 index++; | 722 index++; |
719 while (!done()) { | 723 while (!done()) { |
720 if (s[index] == "\\") { | 724 if (s[index] == "\\") { |
721 if (index + 1 == s.length) { | 725 if (index + 1 == s.length) { |
722 throw new HttpException("Failed to parse header value"); | 726 throw new HttpException("Failed to parse header value"); |
723 } | 727 } |
724 if (preserveBackslash && s[index + 1] != "\"") { | 728 if (preserveBackslash && s[index + 1] != "\"") { |
725 sb.write(s[index]); | 729 sb.write(s[index]); |
726 } | 730 } |
727 index++; | 731 index++; |
728 } else if (s[index] == "\"") { | 732 } else if (s[index] == "\"") { |
729 index++; | 733 index++; |
730 break; | 734 break; |
731 } | 735 } |
732 sb.write(s[index]); | 736 sb.write(s[index]); |
733 index++; | 737 index++; |
734 } | 738 } |
735 return sb.toString(); | 739 return sb.toString(); |
736 } else { | 740 } else { |
737 // Parse non-quoted value. | 741 // Parse non-quoted value. |
738 return parseValue(); | 742 var val = parseValue(); |
| 743 return val == "" ? null : val; |
739 } | 744 } |
740 } | 745 } |
741 | 746 |
742 while (!done()) { | 747 while (!done()) { |
743 skipWS(); | 748 skipWS(); |
744 if (done()) return; | 749 if (done()) return; |
745 String name = parseParameterName(); | 750 String name = parseParameterName(); |
746 skipWS(); | 751 skipWS(); |
747 expect("="); | 752 maybeExpect("="); |
748 skipWS(); | 753 skipWS(); |
749 String value = parseParameterValue(); | 754 String value = parseParameterValue(); |
750 if (name == 'charset' && this is _ContentType) { | 755 if (name == 'charset' && this is _ContentType) { |
751 // Charset parameter of ContentTypes are always lower-case. | 756 // Charset parameter of ContentTypes are always lower-case. |
752 value = value.toLowerCase(); | 757 value = value.toLowerCase(); |
753 } | 758 } |
754 parameters[name] = value; | 759 parameters[name] = value; |
755 skipWS(); | 760 skipWS(); |
756 if (done()) return; | 761 if (done()) return; |
| 762 // TODO: Implement support for multi-valued parameters. |
| 763 if(s[index] == ",") return; |
757 expect(parameterSeparator); | 764 expect(parameterSeparator); |
758 } | 765 } |
759 } | 766 } |
760 | 767 |
761 skipWS(); | 768 skipWS(); |
762 _value = parseValue(); | 769 _value = parseValue(); |
763 skipWS(); | 770 skipWS(); |
764 if (done()) return; | 771 if (done()) return; |
765 maybeExpect(parameterSeparator); | 772 maybeExpect(parameterSeparator); |
766 parseParameters(); | 773 parseParameters(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 (codeUnit >= 0x23 && codeUnit <= 0x2B) || | 977 (codeUnit >= 0x23 && codeUnit <= 0x2B) || |
971 (codeUnit >= 0x2D && codeUnit <= 0x3A) || | 978 (codeUnit >= 0x2D && codeUnit <= 0x3A) || |
972 (codeUnit >= 0x3C && codeUnit <= 0x5B) || | 979 (codeUnit >= 0x3C && codeUnit <= 0x5B) || |
973 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { | 980 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { |
974 throw new FormatException( | 981 throw new FormatException( |
975 "Invalid character in cookie value, code unit: '$codeUnit'"); | 982 "Invalid character in cookie value, code unit: '$codeUnit'"); |
976 } | 983 } |
977 } | 984 } |
978 } | 985 } |
979 } | 986 } |
OLD | NEW |