Chromium Code Reviews| Index: pkg/http/lib/src/multipart_request.dart |
| diff --git a/pkg/http/lib/src/multipart_request.dart b/pkg/http/lib/src/multipart_request.dart |
| index 051ac76b5701d1054f2cc8791991e7ed44414705..cde70a8377e10728d16829050260f3f984cd308b 100644 |
| --- a/pkg/http/lib/src/multipart_request.dart |
| +++ b/pkg/http/lib/src/multipart_request.dart |
| @@ -5,7 +5,6 @@ |
| library multipart_request; |
| import 'dart:async'; |
| -import 'dart:io'; |
| import 'dart:math'; |
| import 'dart:utf'; |
| @@ -36,7 +35,7 @@ class MultipartRequest extends BaseRequest { |
| /// The total length of the multipart boundaries used when building the |
| /// request body. According to http://tools.ietf.org/html/rfc1341.html, this |
| /// can't be longer than 70. |
| - static final int _BOUNDARY_LENGTH = 70; |
| + static const int _BOUNDARY_LENGTH = 70; |
| static final Random _random = new Random(); |
| @@ -75,7 +74,7 @@ class MultipartRequest extends BaseRequest { |
| return length + "--".length + _BOUNDARY_LENGTH + "--\r\n".length; |
| } |
| - set contentLength(int value) { |
| + void set contentLength(int value) { |
| throw new UnsupportedError("Cannot set the contentLength property of " |
| "multipart requests."); |
| } |
| @@ -84,7 +83,7 @@ class MultipartRequest extends BaseRequest { |
| /// that will emit the request body. |
| ByteStream finalize() { |
| // TODO(nweiz): freeze fields and files |
| - var boundary = _boundaryString(_BOUNDARY_LENGTH); |
| + var boundary = _boundaryString(); |
| headers['content-type'] = 'multipart/form-data; boundary="$boundary"'; |
| headers['content-transfer-encoding'] = 'binary'; |
| super.finalize(); |
| @@ -123,7 +122,7 @@ class MultipartRequest extends BaseRequest { |
| /// All character codes that are valid in multipart boundaries. From |
| /// http://tools.ietf.org/html/rfc2046#section-5.1.1. |
| - static final List<int> _BOUNDARY_CHARACTERS = const <int>[ |
| + static const List<int> _BOUNDARY_CHARACTERS = const <int>[ |
| 39, 40, 41, 43, 95, 44, 45, 46, 47, 58, 61, 63, 48, 49, 50, 51, 52, 53, 54, |
| 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, |
| @@ -157,15 +156,13 @@ class MultipartRequest extends BaseRequest { |
| return '$header\r\n\r\n'; |
| } |
| - /// Returns a randomly-generated multipart boundary string of the given |
| - /// [length]. |
| - String _boundaryString(int length) { |
| + /// Returns a randomly-generated multipart boundary string |
| + String _boundaryString() { |
| var prefix = "dart-http-boundary-"; |
| - var list = new List<int>(length - prefix.length); |
| - for (var i = 0; i < list.length; i++) { |
| - list[i] = _BOUNDARY_CHARACTERS[ |
| - _random.nextInt(_BOUNDARY_CHARACTERS.length)]; |
| - } |
| + var list = new List<int>.generate(_BOUNDARY_LENGTH - prefix.length, |
| + (index) => |
| + _BOUNDARY_CHARACTERS[_random.nextInt(_BOUNDARY_CHARACTERS.length)], |
| + growable: false); |
|
nweiz
2013/07/23 22:19:58
style nit: indent -2
|
| return "$prefix${new String.fromCharCodes(list)}"; |
| } |
| } |