| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 _HttpUtils { | 7 class _HttpUtils { |
| 8 static String decodeUrlEncodedString(String urlEncoded) { | 8 static String decodeUrlEncodedString( |
| 9 String urlEncoded, |
| 10 {Encoding encoding: Encoding.UTF_8}) { |
| 9 // First check the string for any encoding. | 11 // First check the string for any encoding. |
| 10 int index = 0; | 12 int index = 0; |
| 11 bool encoded = false; | 13 bool encoded = false; |
| 12 while (!encoded && index < urlEncoded.length) { | 14 while (!encoded && index < urlEncoded.length) { |
| 13 encoded = urlEncoded[index] == "+" || urlEncoded[index] == "%"; | 15 encoded = urlEncoded[index] == "+" || urlEncoded[index] == "%"; |
| 14 index++; | 16 index++; |
| 15 } | 17 } |
| 16 if (!encoded) return urlEncoded; | 18 if (!encoded) return urlEncoded; |
| 17 index--; | 19 index--; |
| 18 | 20 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 throw new ArgumentError("Invalid URL encoding"); | 42 throw new ArgumentError("Invalid URL encoding"); |
| 41 } | 43 } |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 bytes.add(byte); | 46 bytes.add(byte); |
| 45 i += 2; | 47 i += 2; |
| 46 } else { | 48 } else { |
| 47 bytes.add(urlEncoded.codeUnitAt(i)); | 49 bytes.add(urlEncoded.codeUnitAt(i)); |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 return decodeUtf8(bytes); | 52 return _decodeString(bytes, encoding); |
| 51 } | 53 } |
| 52 | 54 |
| 53 static Map<String, String> splitQueryString(String queryString) { | 55 static Map<String, String> splitQueryString( |
| 56 String queryString, |
| 57 {Encoding encoding: Encoding.UTF_8}) { |
| 54 Map<String, String> result = new Map<String, String>(); | 58 Map<String, String> result = new Map<String, String>(); |
| 55 int currentPosition = 0; | 59 int currentPosition = 0; |
| 56 int length = queryString.length; | 60 int length = queryString.length; |
| 57 | 61 |
| 58 while (currentPosition < length) { | 62 while (currentPosition < length) { |
| 59 | 63 |
| 60 // Find the first equals character between current position and | 64 // Find the first equals character between current position and |
| 61 // the provided end. | 65 // the provided end. |
| 62 int indexOfEquals(int end) { | 66 int indexOfEquals(int end) { |
| 63 int index = currentPosition; | 67 int index = currentPosition; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 92 String value; | 96 String value; |
| 93 if (equalspos == -1) { | 97 if (equalspos == -1) { |
| 94 name = queryString.substring(currentPosition, seppos); | 98 name = queryString.substring(currentPosition, seppos); |
| 95 value = ''; | 99 value = ''; |
| 96 } else { | 100 } else { |
| 97 name = queryString.substring(currentPosition, equalspos); | 101 name = queryString.substring(currentPosition, equalspos); |
| 98 value = queryString.substring(equalspos + 1, seppos); | 102 value = queryString.substring(equalspos + 1, seppos); |
| 99 } | 103 } |
| 100 currentPosition = seppos + 1; // This also works when seppos == length. | 104 currentPosition = seppos + 1; // This also works when seppos == length. |
| 101 if (name == '') continue; | 105 if (name == '') continue; |
| 102 result[_HttpUtils.decodeUrlEncodedString(name)] = | 106 result[_HttpUtils.decodeUrlEncodedString(name, encoding: encoding)] = |
| 103 _HttpUtils.decodeUrlEncodedString(value); | 107 _HttpUtils.decodeUrlEncodedString(value, encoding: encoding); |
| 104 } | 108 } |
| 105 return result; | 109 return result; |
| 106 } | 110 } |
| 107 | 111 |
| 108 // From RFC 2616 section "3.3.1 Full Date" | 112 // From RFC 2616 section "3.3.1 Full Date" |
| 109 // HTTP-date = rfc1123-date | rfc850-date | asctime-date | 113 // HTTP-date = rfc1123-date | rfc850-date | asctime-date |
| 110 // rfc1123-date = wkday "," SP date1 SP time SP "GMT" | 114 // rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
| 111 // rfc850-date = weekday "," SP date2 SP time SP "GMT" | 115 // rfc850-date = weekday "," SP date2 SP time SP "GMT" |
| 112 // asctime-date = wkday SP date3 SP time SP 4DIGIT | 116 // asctime-date = wkday SP date3 SP time SP 4DIGIT |
| 113 // date1 = 2DIGIT SP month SP 4DIGIT | 117 // date1 = 2DIGIT SP month SP 4DIGIT |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 while ((amp = input.indexOf('&', offset)) >= 0) { | 423 while ((amp = input.indexOf('&', offset)) >= 0) { |
| 420 buffer.write(input.substring(offset, amp)); | 424 buffer.write(input.substring(offset, amp)); |
| 421 int end = input.indexOf(';', amp); | 425 int end = input.indexOf(';', amp); |
| 422 parse(amp, end); | 426 parse(amp, end); |
| 423 offset = end + 1; | 427 offset = end + 1; |
| 424 } | 428 } |
| 425 buffer.write(input.substring(offset)); | 429 buffer.write(input.substring(offset)); |
| 426 return buffer.toString(); | 430 return buffer.toString(); |
| 427 } | 431 } |
| 428 } | 432 } |
| OLD | NEW |