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

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: Final cleanup Created 7 years, 6 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/base_request.dart ('k') | pkg/http/lib/src/request.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) 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 =
141 'content-disposition: form-data; name="${Uri.encodeFull(name)}"';
142 if (!isPlainAscii(value)) { 142 if (!isPlainAscii(value)) {
143 header = '$header\r\ncontent-type: text/plain; charset=utf-8'; 143 header = '$header\r\ncontent-type: text/plain; charset=utf-8';
144 } 144 }
145 return '$header\r\n\r\n'; 145 return '$header\r\n\r\n';
146 } 146 }
147 147
148 /// Returns the header string for a file. The return value is guaranteed to 148 /// Returns the header string for a file. The return value is guaranteed to
149 /// contain only ASCII characters. 149 /// contain only ASCII characters.
150 String _headerForFile(MultipartFile file) { 150 String _headerForFile(MultipartFile file) {
151 var header = 'content-type: ${file.contentType}\r\n' 151 var header = 'content-type: ${file.contentType}\r\n'
152 'content-disposition: form-data; name="${encodeUri(file.field)}"'; 152 'content-disposition: form-data; name="${Uri.encodeFull(file.field)}"';
153 153
154 if (file.filename != null) { 154 if (file.filename != null) {
155 header = '$header; filename="${encodeUri(file.filename)}"'; 155 header = '$header; filename="${Uri.encodeFull(file.filename)}"';
156 } 156 }
157 return '$header\r\n\r\n'; 157 return '$header\r\n\r\n';
158 } 158 }
159 159
160 /// Returns a randomly-generated multipart boundary string of the given 160 /// Returns a randomly-generated multipart boundary string of the given
161 /// [length]. 161 /// [length].
162 String _boundaryString(int length) { 162 String _boundaryString(int length) {
163 var prefix = "dart-http-boundary-"; 163 var prefix = "dart-http-boundary-";
164 var list = new List<int>(length - prefix.length); 164 var list = new List<int>(length - prefix.length);
165 for (var i = 0; i < list.length; i++) { 165 for (var i = 0; i < list.length; i++) {
166 list[i] = _BOUNDARY_CHARACTERS[ 166 list[i] = _BOUNDARY_CHARACTERS[
167 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; 167 _random.nextInt(_BOUNDARY_CHARACTERS.length)];
168 } 168 }
169 return "$prefix${new String.fromCharCodes(list)}"; 169 return "$prefix${new String.fromCharCodes(list)}";
170 } 170 }
171 } 171 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/base_request.dart ('k') | pkg/http/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698