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

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

Issue 18031023: Remove _BufferList from dart:io and now use BytesBuilder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use takeBytes not toBytes. Created 7 years, 5 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) 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 _HttpBodyHandlerTransformer 7 class _HttpBodyHandlerTransformer
8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> { 8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> {
9 final Encoding _defaultEncoding; 9 final Encoding _defaultEncoding;
10 _HttpBodyHandlerTransformer(this._defaultEncoding); 10 _HttpBodyHandlerTransformer(this._defaultEncoding);
(...skipping 26 matching lines...) Expand all
37 .then((body) => new _HttpClientResponseBody(response, body)); 37 .then((body) => new _HttpClientResponseBody(response, body));
38 } 38 }
39 39
40 static Future<HttpBody> process(Stream<List<int>> stream, 40 static Future<HttpBody> process(Stream<List<int>> stream,
41 HttpHeaders headers, 41 HttpHeaders headers,
42 Encoding defaultEncoding) { 42 Encoding defaultEncoding) {
43 ContentType contentType = headers.contentType; 43 ContentType contentType = headers.contentType;
44 44
45 Future<HttpBody> asBinary() { 45 Future<HttpBody> asBinary() {
46 return stream 46 return stream
47 .fold(new _BufferList(), (buffer, data) => buffer..add(data)) 47 .fold(new BytesBuilder(), (builder, data) => builder..add(data))
48 .then((buffer) => new _HttpBody(contentType, 48 .then((builder) => new _HttpBody(contentType,
49 "binary", 49 "binary",
50 buffer.readBytes())); 50 builder.takeBytes()));
51 } 51 }
52 52
53 Future<HttpBody> asText(Encoding defaultEncoding) { 53 Future<HttpBody> asText(Encoding defaultEncoding) {
54 var encoding; 54 var encoding;
55 var charset = contentType.charset; 55 var charset = contentType.charset;
56 if (charset != null) encoding = Encoding.fromName(charset); 56 if (charset != null) encoding = Encoding.fromName(charset);
57 if (encoding == null) encoding = defaultEncoding; 57 if (encoding == null) encoding = defaultEncoding;
58 return stream 58 return stream
59 .transform(new StringDecoder(encoding)) 59 .transform(new StringDecoder(encoding))
60 .fold(new StringBuffer(), (buffer, data) => buffer..write(data)) 60 .fold(new StringBuffer(), (buffer, data) => buffer..write(data))
61 .then((buffer) => new _HttpBody(contentType, 61 .then((buffer) => new _HttpBody(contentType,
62 "text", 62 "text",
63 buffer.toString())); 63 buffer.toString()));
64 } 64 }
65 65
66 Future<HttpBody> asFormData() { 66 Future<HttpBody> asFormData() {
67 return stream 67 return stream
68 .transform(new MimeMultipartTransformer( 68 .transform(new MimeMultipartTransformer(
69 contentType.parameters['boundary'])) 69 contentType.parameters['boundary']))
70 .map((HttpMultipartFormData.parse)) 70 .map((HttpMultipartFormData.parse))
71 .map((multipart) { 71 .map((multipart) {
72 var future; 72 var future;
73 if (multipart.isText) { 73 if (multipart.isText) {
74 future = multipart 74 future = multipart
75 .fold(new StringBuffer(), (b, s) => b..write(s)) 75 .fold(new StringBuffer(), (b, s) => b..write(s))
76 .then((b) => b.toString()); 76 .then((b) => b.toString());
77 } else { 77 } else {
78 future = multipart 78 future = multipart
79 .fold(new _BufferList(), (b, d) => b..add(d)) 79 .fold(new BytesBuilder(), (b, d) => b..add(d))
80 .then((b) => b.readBytes()); 80 .then((b) => b.takeBytes());
81 } 81 }
82 return future.then((data) { 82 return future.then((data) {
83 var filename = 83 var filename =
84 multipart.contentDisposition.parameters['filename']; 84 multipart.contentDisposition.parameters['filename'];
85 if (filename != null) { 85 if (filename != null) {
86 data = new _HttpBodyFileUpload(multipart.contentType, 86 data = new _HttpBodyFileUpload(multipart.contentType,
87 filename, 87 filename,
88 data); 88 data);
89 } 89 }
90 return [multipart.contentDisposition.parameters['name'], data]; 90 return [multipart.contentDisposition.parameters['name'], data];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) 190 _HttpClientResponseBody(HttpClientResponse response, HttpBody body)
191 : super(body.contentType, body.type, body.body), 191 : super(body.contentType, body.type, body.body),
192 this.response = response; 192 this.response = response;
193 193
194 int get statusCode => response.statusCode; 194 int get statusCode => response.statusCode;
195 195
196 String get reasonPhrase => response.reasonPhrase; 196 String get reasonPhrase => response.reasonPhrase;
197 197
198 HttpHeaders get headers => response.headers; 198 HttpHeaders get headers => response.headers;
199 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698