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: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'; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 writeUtf8(String string) => controller.add(encodeUtf8(string)); | 104 writeUtf8(String string) => controller.add(encodeUtf8(string)); |
105 writeLine() => controller.add([13, 10]); // \r\n | 105 writeLine() => controller.add([13, 10]); // \r\n |
106 | 106 |
107 fields.forEach((name, value) { | 107 fields.forEach((name, value) { |
108 writeAscii('--$boundary\r\n'); | 108 writeAscii('--$boundary\r\n'); |
109 writeAscii(_headerForField(name, value)); | 109 writeAscii(_headerForField(name, value)); |
110 writeUtf8(value); | 110 writeUtf8(value); |
111 writeLine(); | 111 writeLine(); |
112 }); | 112 }); |
113 | 113 |
114 Futures.forEach(_files.collection, (file) { | 114 Future.forEach(_files.collection, (file) { |
115 writeAscii('--$boundary\r\n'); | 115 writeAscii('--$boundary\r\n'); |
116 writeAscii(_headerForFile(file)); | 116 writeAscii(_headerForFile(file)); |
117 return writeStreamToSink(file.finalize(), controller) | 117 return writeStreamToSink(file.finalize(), controller) |
118 .then((_) => writeLine()); | 118 .then((_) => writeLine()); |
119 }).then((_) { | 119 }).then((_) { |
120 // TODO(nweiz): pass any errors propagated through this future on to | 120 // TODO(nweiz): pass any errors propagated through this future on to |
121 // the stream. See issue 3657. | 121 // the stream. See issue 3657. |
122 writeAscii('--$boundary--\r\n'); | 122 writeAscii('--$boundary--\r\n'); |
123 controller.close(); | 123 controller.close(); |
124 }); | 124 }); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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>.fixedLength(length - prefix.length); | 168 var list = new List<int>.fixedLength(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 } |
OLD | NEW |