| 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 | 7 |
| 8 class _HttpMultipartFormData extends Stream implements HttpMultipartFormData { | 8 class _HttpMultipartFormData extends Stream implements HttpMultipartFormData { |
| 9 final ContentType contentType; | 9 final ContentType contentType; |
| 10 final HeaderValue contentDisposition; | 10 final HeaderValue contentDisposition; |
| 11 final HeaderValue contentTransferEncoding; | 11 final HeaderValue contentTransferEncoding; |
| 12 | 12 |
| 13 final MimeMultipart _mimeMultipart; | 13 final MimeMultipart _mimeMultipart; |
| 14 | 14 |
| 15 bool _isText = false; | 15 bool _isText = false; |
| 16 | 16 |
| 17 Stream _stream; | 17 Stream _stream; |
| 18 | 18 |
| 19 _HttpMultipartFormData(ContentType this.contentType, | 19 _HttpMultipartFormData(ContentType this.contentType, |
| 20 HeaderValue this.contentDisposition, | 20 HeaderValue this.contentDisposition, |
| 21 HeaderValue this.contentTransferEncoding, | 21 HeaderValue this.contentTransferEncoding, |
| 22 MimeMultipart this._mimeMultipart) { | 22 MimeMultipart this._mimeMultipart) { |
| 23 _stream = _mimeMultipart; | 23 _stream = _mimeMultipart; |
| 24 if (contentTransferEncoding != null) { | 24 if (contentTransferEncoding != null) { |
| 25 // TODO(ajohnsen): Support BASE64, etc. | 25 // TODO(ajohnsen): Support BASE64, etc. |
| 26 throw new HttpException("Unsupported contentTransferEncoding: " | 26 throw new HttpException("Unsupported contentTransferEncoding: " |
| 27 "${contentTransferEncoding.value}"); | 27 "${contentTransferEncoding.value}"); |
| 28 } | 28 } |
| 29 | 29 |
| 30 if (contentType == null || contentType.primaryType == 'text') { | 30 if (contentType == null || |
| 31 contentType.primaryType == 'text' || |
| 32 contentType.mimeType == 'application/json') { |
| 31 _isText = true; | 33 _isText = true; |
| 32 StringBuffer buffer = new StringBuffer(); | 34 StringBuffer buffer = new StringBuffer(); |
| 33 Encoding encoding; | 35 Encoding encoding; |
| 34 if (contentType != null) { | 36 if (contentType != null) { |
| 35 encoding = Encoding.fromName(contentType.charset); | 37 encoding = Encoding.fromName(contentType.charset); |
| 36 } | 38 } |
| 37 if (encoding == null) encoding = Encoding.ISO_8859_1; | 39 if (encoding == null) encoding = Encoding.ISO_8859_1; |
| 38 _stream = _stream | 40 _stream = _stream |
| 39 .transform(new StringDecoder(encoding)) | 41 .transform(new StringDecoder(encoding)) |
| 40 .expand((data) { | 42 .expand((data) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 onDone: onDone, | 93 onDone: onDone, |
| 92 onError: onError, | 94 onError: onError, |
| 93 cancelOnError: cancelOnError); | 95 cancelOnError: cancelOnError); |
| 94 } | 96 } |
| 95 | 97 |
| 96 String value(String name) { | 98 String value(String name) { |
| 97 return _mimeMultipart.headers[name]; | 99 return _mimeMultipart.headers[name]; |
| 98 } | 100 } |
| 99 } | 101 } |
| 100 | 102 |
| OLD | NEW |