Chromium Code Reviews| Index: sdk/lib/io/http_multipart_form_data_impl.dart |
| diff --git a/sdk/lib/io/http_multipart_form_data_impl.dart b/sdk/lib/io/http_multipart_form_data_impl.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c102e5b705421b8984bf80ca45e544436f87b91 |
| --- /dev/null |
| +++ b/sdk/lib/io/http_multipart_form_data_impl.dart |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart.io; |
| + |
| + |
| +class _HttpMultipartFormData extends Stream implements HttpMultipartFormData { |
| + final ContentType contentType; |
| + final HeaderValue contentDisposition; |
| + final HeaderValue contentTransferEncoding; |
| + |
| + final MimeMultipart _mimeMultipart; |
| + |
| + bool _isText = false; |
| + |
| + Stream _stream; |
| + |
| + _HttpMultipartFormData(ContentType this.contentType, |
| + HeaderValue this.contentDisposition, |
| + HeaderValue this.contentTransferEncoding, |
| + MimeMultipart this._mimeMultipart) { |
| + _stream = _mimeMultipart; |
| + if (contentTransferEncoding != null) { |
|
Søren Gjesse
2013/05/06 12:28:10
Throw here for now?
Anders Johnsen
2013/05/06 13:38:16
Done.
|
| + // TODO(ajohnsen): Support BASE64, etc. |
| + return; |
| + } |
| + |
| + if (contentType == null || contentType.primaryType == 'text') { |
| + _isText = true; |
| + StringBuffer buffer = new StringBuffer(); |
| + _stream = _stream |
|
Søren Gjesse
2013/05/06 12:28:10
Use the content type charset for decoding if provi
Anders Johnsen
2013/05/06 13:38:16
Done.
|
| + .transform(new StringDecoder(Encoding.ISO_8859_1)) |
| + .expand((data) { |
|
Søren Gjesse
2013/05/06 12:28:10
What if the HTML entites cross data boundaries?
Anders Johnsen
2013/05/06 13:38:16
That's what the 'null' check is for. It returns nu
|
| + buffer.write(data); |
| + var out = _HttpUtils.parseHttpEntityString(buffer.toString()); |
| + if (out != null) { |
| + buffer = new StringBuffer(); |
| + return [out]; |
| + } |
| + return const []; |
| + }); |
| + } |
| + } |
| + |
| + bool get isText => _isText; |
| + bool get isBinary => !_isText; |
| + |
| + static HttpMultipartFormData parse(MimeMultipart multipart) { |
| + var type; |
| + var encoding; |
| + var disposition; |
| + var remaining = new Map<String, String>(); |
| + for (String key in multipart.headers.keys) { |
| + switch (key) { |
| + case HttpHeaders.CONTENT_TYPE: |
| + type = ContentType.parse(multipart.headers[key]); |
| + break; |
| + |
| + case 'content-transfer-encoding': |
| + encoding = HeaderValue.parse(multipart.headers[key]); |
| + break; |
| + |
| + case 'content-disposition': |
| + disposition = HeaderValue.parse(multipart.headers[key]); |
| + break; |
| + |
| + default: |
| + remaining[key] = headers[key]; |
| + break; |
| + } |
| + } |
| + if (disposition == null) { |
| + throw new HttpException( |
| + "Mime Multipart doesn't contain a Content-Disposition header value"); |
| + } |
| + return new _HttpMultipartFormData(type, disposition, encoding, multipart); |
| + } |
| + |
| + StreamSubscription listen(void onData(data), |
| + {void onDone(), |
| + void onError(error), |
| + bool cancelOnError}) { |
| + return _stream.listen(onData, |
| + onDone: onDone, |
| + onError: onError, |
| + cancelOnError: cancelOnError); |
| + } |
| + |
| + String value(String name) { |
| + return _mimeMultipart.headers[name]; |
| + } |
| +} |
| + |