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

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

Issue 16019002: Merge the dart:uri library into dart:core and update the Uri class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing files Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:math'; 9 import 'dart:math';
10 import 'dart:uri';
11 import 'dart:utf'; 10 import 'dart:utf';
12 11
13 import 'base_request.dart'; 12 import 'base_request.dart';
14 import 'byte_stream.dart'; 13 import 'byte_stream.dart';
15 import 'multipart_file.dart'; 14 import 'multipart_file.dart';
16 import 'utils.dart'; 15 import 'utils.dart';
17 16
18 /// 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],
19 /// which function as normal form fields, and (potentially streamed) binary 18 /// which function as normal form fields, and (potentially streamed) binary
20 /// [files]. 19 /// [files].
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 130 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
132 119, 120, 121, 122 131 119, 120, 121, 122
133 ]; 132 ];
134 133
135 /// Returns the header string for a field. The return value is guaranteed to 134 /// Returns the header string for a field. The return value is guaranteed to
136 /// contain only ASCII characters. 135 /// contain only ASCII characters.
137 String _headerForField(String name, String value) { 136 String _headerForField(String name, String value) {
138 // http://tools.ietf.org/html/rfc2388 mandates some complex encodings for 137 // http://tools.ietf.org/html/rfc2388 mandates some complex encodings for
139 // field names and file names, but in practice user agents seem to just 138 // field names and file names, but in practice user agents seem to just
140 // URL-encode them so we do the same. 139 // URL-encode them so we do the same.
141 var header = 'content-disposition: form-data; name="${encodeUri(name)}"'; 140 var header = 'content-disposition: form-data; name="${Uri.encodeFull(name)}" ';
nweiz 2013/05/24 18:59:10 long line
Søren Gjesse 2013/05/27 10:47:21 Done.
142 if (!isPlainAscii(value)) { 141 if (!isPlainAscii(value)) {
143 header = '$header\r\ncontent-type: text/plain; charset=utf-8'; 142 header = '$header\r\ncontent-type: text/plain; charset=utf-8';
144 } 143 }
145 return '$header\r\n\r\n'; 144 return '$header\r\n\r\n';
146 } 145 }
147 146
148 /// Returns the header string for a file. The return value is guaranteed to 147 /// Returns the header string for a file. The return value is guaranteed to
149 /// contain only ASCII characters. 148 /// contain only ASCII characters.
150 String _headerForFile(MultipartFile file) { 149 String _headerForFile(MultipartFile file) {
151 var header = 'content-type: ${file.contentType}\r\n' 150 var header = 'content-type: ${file.contentType}\r\n'
152 'content-disposition: form-data; name="${encodeUri(file.field)}"'; 151 'content-disposition: form-data; name="${Uri.encodeFull(file.field)}"';
153 152
154 if (file.filename != null) { 153 if (file.filename != null) {
155 header = '$header; filename="${encodeUri(file.filename)}"'; 154 header = '$header; filename="${Uri.encodeFull(file.filename)}"';
156 } 155 }
157 return '$header\r\n\r\n'; 156 return '$header\r\n\r\n';
158 } 157 }
159 158
160 /// Returns a randomly-generated multipart boundary string of the given 159 /// Returns a randomly-generated multipart boundary string of the given
161 /// [length]. 160 /// [length].
162 String _boundaryString(int length) { 161 String _boundaryString(int length) {
163 var prefix = "dart-http-boundary-"; 162 var prefix = "dart-http-boundary-";
164 var list = new List<int>(length - prefix.length); 163 var list = new List<int>(length - prefix.length);
165 for (var i = 0; i < list.length; i++) { 164 for (var i = 0; i < list.length; i++) {
166 list[i] = _BOUNDARY_CHARACTERS[ 165 list[i] = _BOUNDARY_CHARACTERS[
167 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; 166 _random.nextInt(_BOUNDARY_CHARACTERS.length)];
168 } 167 }
169 return "$prefix${new String.fromCharCodes(list)}"; 168 return "$prefix${new String.fromCharCodes(list)}";
170 } 169 }
171 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698