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

Unified Diff: pkg/http_server/lib/src/http_body_impl.dart

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http_server/lib/src/http_body.dart ('k') | pkg/http_server/lib/src/http_multipart_form_data_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/lib/src/http_body_impl.dart
diff --git a/pkg/http_server/lib/src/http_body_impl.dart b/pkg/http_server/lib/src/http_body_impl.dart
index 5d52874b1bd4baf89e8bd64ae278db467ad341df..c48db0378a9c9712936a387de505e7e6373b17b3 100644
--- a/pkg/http_server/lib/src/http_body_impl.dart
+++ b/pkg/http_server/lib/src/http_body_impl.dart
@@ -53,10 +53,10 @@ class _HttpBodyHandler {
Future<HttpBody> asText(Encoding defaultEncoding) {
var encoding;
var charset = contentType.charset;
- if (charset != null) encoding = Encoding.fromName(charset);
+ if (charset != null) encoding = Encoding.getByName(charset);
if (encoding == null) encoding = defaultEncoding;
return stream
- .transform(new StringDecoder(encoding))
+ .transform(encoding.decoder)
.fold(new StringBuffer(), (buffer, data) => buffer..write(data))
.then((buffer) => new _HttpBody(contentType,
"text",
@@ -107,21 +107,21 @@ class _HttpBodyHandler {
switch (contentType.primaryType) {
case "text":
- return asText(Encoding.ASCII);
+ return asText(ASCII);
case "application":
switch (contentType.subType) {
case "json":
- return asText(Encoding.UTF_8)
+ return asText(UTF8)
.then((body) => new _HttpBody(contentType,
"json",
JSON.parse(body.body)));
case "x-www-form-urlencoded":
- return asText(Encoding.ASCII)
+ return asText(ASCII)
.then((body) {
var map = Uri.splitQueryString(body.body,
- decode: (s) => _decodeString(s, defaultEncoding));
+ decode: (s) => defaultEncoding.decode(s));
var result = {};
for (var key in map.keys) {
result[key] = map[key];
@@ -150,24 +150,6 @@ class _HttpBodyHandler {
return asBinary();
}
-
- // Utility function to synchronously decode a list of bytes.
- static String _decodeString(List<int> bytes,
- [Encoding encoding = Encoding.UTF_8]) {
- if (bytes.length == 0) return "";
- var string;
- var error;
- var controller = new StreamController(sync: true);
- controller.stream
- .transform(new StringDecoder(encoding))
- .listen((data) => string = data,
- onError: (e) => error = e);
- controller.add(bytes);
- controller.close();
- if (error != null) throw error;
- assert(string != null);
- return string;
- }
}
class _HttpBodyFileUpload implements HttpBodyFileUpload {
« no previous file with comments | « pkg/http_server/lib/src/http_body.dart ('k') | pkg/http_server/lib/src/http_multipart_form_data_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698