Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: sdk/lib/io/http_utils.dart

Issue 15221002: Add optional defaultEncoding to HttpBodyHandler, as a way to override default encoding for 'applica… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 while (currentPosition < queryString.length) { 60 while (currentPosition < queryString.length) {
57 int position = queryString.indexOf("=", currentPosition); 61 int position = queryString.indexOf("=", currentPosition);
58 if (position == -1) { 62 if (position == -1) {
59 break; 63 break;
60 } 64 }
61 String name = queryString.substring(currentPosition, position); 65 String name = queryString.substring(currentPosition, position);
62 currentPosition = position + 1; 66 currentPosition = position + 1;
63 position = queryString.indexOf("&", currentPosition); 67 position = queryString.indexOf("&", currentPosition);
64 String value; 68 String value;
65 if (position == -1) { 69 if (position == -1) {
66 value = queryString.substring(currentPosition); 70 value = queryString.substring(currentPosition);
67 currentPosition = queryString.length; 71 currentPosition = queryString.length;
68 } else { 72 } else {
69 value = queryString.substring(currentPosition, position); 73 value = queryString.substring(currentPosition, position);
70 currentPosition = position + 1; 74 currentPosition = position + 1;
71 } 75 }
72 result[_HttpUtils.decodeUrlEncodedString(name)] = 76 result[_HttpUtils.decodeUrlEncodedString(name, encoding: encoding)] =
73 _HttpUtils.decodeUrlEncodedString(value); 77 _HttpUtils.decodeUrlEncodedString(value, encoding: encoding);
74 } 78 }
75 return result; 79 return result;
76 } 80 }
77 81
78 // From RFC 2616 section "3.3.1 Full Date" 82 // From RFC 2616 section "3.3.1 Full Date"
79 // HTTP-date = rfc1123-date | rfc850-date | asctime-date 83 // HTTP-date = rfc1123-date | rfc850-date | asctime-date
80 // rfc1123-date = wkday "," SP date1 SP time SP "GMT" 84 // rfc1123-date = wkday "," SP date1 SP time SP "GMT"
81 // rfc850-date = weekday "," SP date2 SP time SP "GMT" 85 // rfc850-date = weekday "," SP date2 SP time SP "GMT"
82 // asctime-date = wkday SP date3 SP time SP 4DIGIT 86 // asctime-date = wkday SP date3 SP time SP 4DIGIT
83 // date1 = 2DIGIT SP month SP 4DIGIT 87 // date1 = 2DIGIT SP month SP 4DIGIT
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 while ((amp = input.indexOf('&', offset)) >= 0) { 393 while ((amp = input.indexOf('&', offset)) >= 0) {
390 buffer.write(input.substring(offset, amp)); 394 buffer.write(input.substring(offset, amp));
391 int end = input.indexOf(';', amp); 395 int end = input.indexOf(';', amp);
392 parse(amp, end); 396 parse(amp, end);
393 offset = end + 1; 397 offset = end + 1;
394 } 398 }
395 buffer.write(input.substring(offset)); 399 buffer.write(input.substring(offset));
396 return buffer.toString(); 400 return buffer.toString();
397 } 401 }
398 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698