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

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

Issue 12440002: Make instances of HeaderValue and ContentType immutable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from nweiz@ Created 7 years, 9 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/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) 2012, 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'; 10 import 'dart:uri';
11 import 'dart:utf'; 11 import 'dart:utf';
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ]; 137 ];
138 138
139 /// Returns the header string for a field. The return value is guaranteed to 139 /// Returns the header string for a field. The return value is guaranteed to
140 /// contain only ASCII characters. 140 /// contain only ASCII characters.
141 String _headerForField(String name, String value) { 141 String _headerForField(String name, String value) {
142 // http://tools.ietf.org/html/rfc2388 mandates some complex encodings for 142 // http://tools.ietf.org/html/rfc2388 mandates some complex encodings for
143 // field names and file names, but in practice user agents seem to just 143 // field names and file names, but in practice user agents seem to just
144 // URL-encode them so we do the same. 144 // URL-encode them so we do the same.
145 var header = 'content-disposition: form-data; name="${encodeUri(name)}"'; 145 var header = 'content-disposition: form-data; name="${encodeUri(name)}"';
146 if (!isPlainAscii(value)) { 146 if (!isPlainAscii(value)) {
147 header = '$header\r\ncontent-type: text/plain; charset=UTF-8'; 147 header = '$header\r\ncontent-type: text/plain; charset=utf-8';
148 } 148 }
149 return '$header\r\n\r\n'; 149 return '$header\r\n\r\n';
150 } 150 }
151 151
152 /// Returns the header string for a file. The return value is guaranteed to 152 /// Returns the header string for a file. The return value is guaranteed to
153 /// contain only ASCII characters. 153 /// contain only ASCII characters.
154 String _headerForFile(MultipartFile file) { 154 String _headerForFile(MultipartFile file) {
155 var header = 'content-type: ${file.contentType}\r\n' 155 var header = 'content-type: ${file.contentType}\r\n'
156 'content-disposition: form-data; name="${encodeUri(file.field)}"'; 156 'content-disposition: form-data; name="${encodeUri(file.field)}"';
157 157
158 if (file.filename != null) { 158 if (file.filename != null) {
159 header = '$header; filename="${encodeUri(file.filename)}"'; 159 header = '$header; filename="${encodeUri(file.filename)}"';
160 } 160 }
161 return '$header\r\n\r\n'; 161 return '$header\r\n\r\n';
162 } 162 }
163 163
164 /// Returns a randomly-generated multipart boundary string of the given 164 /// Returns a randomly-generated multipart boundary string of the given
165 /// [length]. 165 /// [length].
166 String _boundaryString(int length) { 166 String _boundaryString(int length) {
167 var prefix = "dart-http-boundary-"; 167 var prefix = "dart-http-boundary-";
168 var list = new List<int>(length - prefix.length); 168 var list = new List<int>(length - prefix.length);
169 for (var i = 0; i < list.length; i++) { 169 for (var i = 0; i < list.length; i++) {
170 list[i] = _BOUNDARY_CHARACTERS[ 170 list[i] = _BOUNDARY_CHARACTERS[
171 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; 171 _random.nextInt(_BOUNDARY_CHARACTERS.length)];
172 } 172 }
173 return "$prefix${new String.fromCharCodes(list)}"; 173 return "$prefix${new String.fromCharCodes(list)}";
174 } 174 }
175 } 175 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/multipart_file.dart ('k') | pkg/http/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698