Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 1cf7853

Browse files
authored
Support 7bit, 8bit, binary transfer-encodings (#61)
Check for transparent encodings and ignore them.
1 parent c24382e commit 1cf7853

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 0.9.8+4-dev
22

3+
* Allow multipart form data with specified encodings that don't require
4+
decoding.
5+
36
# 0.9.8+3
47

58
* Prepare for `HttpClientResponse` SDK change (implements `Stream<Uint8List>`

lib/src/http_multipart_form_data_impl.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ class HttpMultipartFormDataImpl extends Stream
2525

2626
Stream _stream;
2727

28+
/// The values which indicate that no incoding was performed.
29+
///
30+
/// https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html
31+
static const _transparentEncodings = ['7bit', '8bit', 'binary'];
32+
2833
HttpMultipartFormDataImpl(
2934
this.contentType,
3035
this.contentDisposition,
3136
this.contentTransferEncoding,
3237
this._mimeMultipart,
3338
Encoding defaultEncoding) {
3439
_stream = _mimeMultipart;
35-
if (contentTransferEncoding != null) {
40+
if (contentTransferEncoding != null &&
41+
!_transparentEncodings
42+
.contains(contentTransferEncoding.value.toLowerCase())) {
3643
// TODO(ajohnsen): Support BASE64, etc.
3744
throw HttpException('Unsupported contentTransferEncoding: '
3845
'${contentTransferEncoding.value}');

test/http_multipart_test.dart

+13
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ Content of file\r
133133
]);
134134
});
135135

136+
test('With content transfer encoding', () async {
137+
var message = '''
138+
\r\n--AaB03x\r
139+
Content-Disposition: form-data; name="submit-name"\r
140+
Content-Transfer-Encoding: 8bit\r
141+
\r
142+
Larry\r
143+
--AaB03x--\r\n''';
144+
145+
await _postDataTest(message.codeUnits, 'multipart/form-data', 'AaB03x',
146+
[FormField('submit-name', 'Larry')]);
147+
});
148+
136149
test('Windows/IE style file upload', () async {
137150
var message = '''
138151
\r\n--AaB03x\r

0 commit comments

Comments
 (0)