| OLD | NEW |
| 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:io'; | 7 import 'dart:io'; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 import 'dart:utf'; | 10 import 'dart:utf'; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 MultipartRequest(String method, Uri url) | 74 MultipartRequest(String method, Uri url) |
| 75 : super(method, url), | 75 : super(method, url), |
| 76 fields = <String>{}, | 76 fields = <String>{}, |
| 77 files = <MultipartFile>[]; | 77 files = <MultipartFile>[]; |
| 78 | 78 |
| 79 /// Freezes all mutable fields and returns an [InputStream] that will emit the | 79 /// Freezes all mutable fields and returns an [InputStream] that will emit the |
| 80 /// request body. | 80 /// request body. |
| 81 InputStream finalize() { | 81 InputStream finalize() { |
| 82 // TODO(nweiz): freeze fields and files | 82 // TODO(nweiz): freeze fields and files |
| 83 var boundary = _boundaryString(_BOUNDARY_LENGTH); | 83 var boundary = _boundaryString(_BOUNDARY_LENGTH); |
| 84 headers['content-type'] = 'multipart/form-data, boundary="$boundary"'; | 84 headers['content-type'] = 'multipart/form-data; boundary="$boundary"'; |
| 85 headers['content-transfer-encoding'] = 'binary'; | 85 headers['content-transfer-encoding'] = 'binary'; |
| 86 super.finalize(); | 86 super.finalize(); |
| 87 | 87 |
| 88 var stream = new ListInputStream(); | 88 var stream = new ListInputStream(); |
| 89 | 89 |
| 90 void writeAscii(String string) { | 90 void writeAscii(String string) { |
| 91 assert(isPlainAscii(string)); | 91 assert(isPlainAscii(string)); |
| 92 stream.write(string.charCodes); | 92 stream.write(string.charCodes); |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 String _boundaryString(int length) { | 157 String _boundaryString(int length) { |
| 158 var prefix = "dart-http-boundary-"; | 158 var prefix = "dart-http-boundary-"; |
| 159 var list = new List<int>(length - prefix.length); | 159 var list = new List<int>(length - prefix.length); |
| 160 for (var i = 0; i < list.length; i++) { | 160 for (var i = 0; i < list.length; i++) { |
| 161 list[i] = _BOUNDARY_CHARACTERS[ | 161 list[i] = _BOUNDARY_CHARACTERS[ |
| 162 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; | 162 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; |
| 163 } | 163 } |
| 164 return "$prefix${new String.fromCharCodes(list)}"; | 164 return "$prefix${new String.fromCharCodes(list)}"; |
| 165 } | 165 } |
| 166 } | 166 } |
| OLD | NEW |