Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: pkg/http/lib/src/multipart_request.dart

Issue 19866007: pkg/http tweaks (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: final nits Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/lib/src/client.dart ('k') | pkg/http/lib/src/streamed_request.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)}";
}
}
« no previous file with comments | « pkg/http/lib/src/client.dart ('k') | pkg/http/lib/src/streamed_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698