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

Side by Side Diff: pkg/http/lib/src/multipart_request.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/multipart_file.dart ('k') | pkg/http/lib/src/response.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library multipart_request; 5 library multipart_request;
6 6
7 import 'dart:async';
7 import 'dart:io'; 8 import 'dart:io';
8 import 'dart:math'; 9 import 'dart:math';
9 import 'dart:uri'; 10 import 'dart:uri';
10 import 'dart:utf'; 11 import 'dart:utf';
11 12
12 import 'base_request.dart'; 13 import 'base_request.dart';
13 import 'multipart_file.dart'; 14 import 'multipart_file.dart';
14 import 'utils.dart'; 15 import 'utils.dart';
15 16
16 /// A `multipart/form-data` request. Such a request has both string [fields], 17 /// A `multipart/form-data` request. Such a request has both string [fields],
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 writeAscii('--$boundary\r\n'); 100 writeAscii('--$boundary\r\n');
100 writeAscii(_headerForField(name, value)); 101 writeAscii(_headerForField(name, value));
101 writeUtf8(value); 102 writeUtf8(value);
102 writeLine(); 103 writeLine();
103 }); 104 });
104 105
105 Futures.forEach(files, (file) { 106 Futures.forEach(files, (file) {
106 writeAscii('--$boundary\r\n'); 107 writeAscii('--$boundary\r\n');
107 writeAscii(_headerForFile(file)); 108 writeAscii(_headerForFile(file));
108 return writeInputToInput(file.finalize(), stream) 109 return writeInputToInput(file.finalize(), stream)
109 .transform((_) => writeLine()); 110 .then((_) => writeLine());
110 }).then((_) { 111 }).then((_) {
111 // TODO(nweiz): pass any errors propagated through this future on to 112 // TODO(nweiz): pass any errors propagated through this future on to
112 // the stream. See issue 3657. 113 // the stream. See issue 3657.
113 writeAscii('--$boundary--\r\n'); 114 writeAscii('--$boundary--\r\n');
114 stream.markEndOfStream(); 115 stream.markEndOfStream();
115 }); 116 });
116 117
117 return stream; 118 return stream;
118 } 119 }
119 120
(...skipping 29 matching lines...) Expand all
149 if (file.filename != null) { 150 if (file.filename != null) {
150 header = '$header; filename="${encodeUri(file.filename)}"'; 151 header = '$header; filename="${encodeUri(file.filename)}"';
151 } 152 }
152 return '$header\r\n\r\n'; 153 return '$header\r\n\r\n';
153 } 154 }
154 155
155 /// Returns a randomly-generated multipart boundary string of the given 156 /// Returns a randomly-generated multipart boundary string of the given
156 /// [length]. 157 /// [length].
157 String _boundaryString(int length) { 158 String _boundaryString(int length) {
158 var prefix = "dart-http-boundary-"; 159 var prefix = "dart-http-boundary-";
159 var list = new List<int>(length - prefix.length); 160 var list = new List<int>.fixedLength(length - prefix.length);
160 for (var i = 0; i < list.length; i++) { 161 for (var i = 0; i < list.length; i++) {
161 list[i] = _BOUNDARY_CHARACTERS[ 162 list[i] = _BOUNDARY_CHARACTERS[
162 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; 163 _random.nextInt(_BOUNDARY_CHARACTERS.length)];
163 } 164 }
164 return "$prefix${new String.fromCharCodes(list)}"; 165 return "$prefix${new String.fromCharCodes(list)}";
165 } 166 }
166 } 167 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/multipart_file.dart ('k') | pkg/http/lib/src/response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698