Chromium Code Reviews| 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 http_server; |
| 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; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 34 StringBuffer buffer = new StringBuffer(); | 34 StringBuffer buffer = new StringBuffer(); |
| 35 Encoding encoding; | 35 Encoding encoding; |
| 36 if (contentType != null) { | 36 if (contentType != null) { |
| 37 encoding = Encoding.fromName(contentType.charset); | 37 encoding = Encoding.fromName(contentType.charset); |
| 38 } | 38 } |
| 39 if (encoding == null) encoding = Encoding.ISO_8859_1; | 39 if (encoding == null) encoding = Encoding.ISO_8859_1; |
| 40 _stream = _stream | 40 _stream = _stream |
| 41 .transform(new StringDecoder(encoding)) | 41 .transform(new StringDecoder(encoding)) |
| 42 .expand((data) { | 42 .expand((data) { |
| 43 buffer.write(data); | 43 buffer.write(data); |
| 44 var out = _HttpUtils.decodeHttpEntityString(buffer.toString()); | 44 var out = _decodeHttpEntityString(buffer.toString()); |
| 45 if (out != null) { | 45 if (out != null) { |
| 46 buffer = new StringBuffer(); | 46 buffer = new StringBuffer(); |
| 47 return [out]; | 47 return [out]; |
| 48 } | 48 } |
| 49 return const []; | 49 return const []; |
| 50 }); | 50 }); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool get isText => _isText; | 54 bool get isText => _isText; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 onDone: onDone, | 93 onDone: onDone, |
| 94 onError: onError, | 94 onError: onError, |
| 95 cancelOnError: cancelOnError); | 95 cancelOnError: cancelOnError); |
| 96 } | 96 } |
| 97 | 97 |
| 98 String value(String name) { | 98 String value(String name) { |
| 99 return _mimeMultipart.headers[name]; | 99 return _mimeMultipart.headers[name]; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 | |
| 104 // Decode a string with HTTP entities. Returns null if the string ends in the | |
| 105 // middle of a http entity. | |
| 106 // TODO(ajohnsen): Provide in dart:io? | |
| 107 String _decodeHttpEntityString(String input) { | |
| 108 int amp = input.lastIndexOf('&'); | |
| 109 if (amp < 0) return input; | |
| 110 int end = input.lastIndexOf(';'); | |
|
Bill Hesse
2013/07/03 11:30:27
or indexOf(';', amp)
Anders Johnsen
2013/07/12 10:45:57
This is gone.
| |
| 111 if (end < amp) return null; | |
| 112 | |
| 113 var buffer = new StringBuffer(); | |
| 114 int offset = 0; | |
| 115 | |
| 116 parse(amp, end) { | |
| 117 switch (input[amp + 1]) { | |
| 118 case '#': | |
| 119 if (input[amp + 2] == 'x') { | |
| 120 buffer.writeCharCode( | |
| 121 int.parse(input.substring(amp + 3, end), radix: 16)); | |
| 122 } else { | |
| 123 buffer.writeCharCode(int.parse(input.substring(amp + 2, end))); | |
| 124 } | |
| 125 break; | |
| 126 | |
| 127 default: | |
| 128 throw new HttpException('Unhandled HTTP entity token'); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 while ((amp = input.indexOf('&', offset)) >= 0) { | |
| 133 buffer.write(input.substring(offset, amp)); | |
| 134 int end = input.indexOf(';', amp); | |
| 135 parse(amp, end); | |
| 136 offset = end + 1; | |
| 137 } | |
| 138 buffer.write(input.substring(offset)); | |
| 139 return buffer.toString(); | |
| 140 } | |
| OLD | NEW |