| OLD | NEW |
| 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 import "package:http_server/http_server.dart"; | 5 import "package:http_server/http_server.dart"; |
| 6 import "package:mime/mime.dart"; | 6 import "package:mime/mime.dart"; |
| 7 import "package:unittest/unittest.dart"; | 7 import "package:unittest/unittest.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:convert'; |
| 10 | 11 |
| 11 class FormField { | 12 class FormField { |
| 12 final String name; | 13 final String name; |
| 13 final value; | 14 final value; |
| 14 final String contentType; | 15 final String contentType; |
| 15 final String filename; | 16 final String filename; |
| 16 | 17 |
| 17 FormField(String this.name, | 18 FormField(String this.name, |
| 18 this.value, | 19 this.value, |
| 19 {String this.contentType, | 20 {String this.contentType, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 | 39 |
| 39 void postDataTest(List<int> message, | 40 void postDataTest(List<int> message, |
| 40 String contentType, | 41 String contentType, |
| 41 String boundary, | 42 String boundary, |
| 42 List<FormField> expectedFields) { | 43 List<FormField> expectedFields) { |
| 43 HttpServer.bind("127.0.0.1", 0).then((server) { | 44 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 44 server.listen((request) { | 45 server.listen((request) { |
| 45 String boundary = request.headers.contentType.parameters['boundary']; | 46 String boundary = request.headers.contentType.parameters['boundary']; |
| 46 request | 47 request |
| 47 .transform(new MimeMultipartTransformer(boundary)) | 48 .transform(new MimeMultipartTransformer(boundary)) |
| 48 .map(HttpMultipartFormData.parse) | 49 .map((part) => HttpMultipartFormData.parse( |
| 50 part, defaultEncoding: LATIN1)) |
| 49 .map((multipart) { | 51 .map((multipart) { |
| 50 var future; | 52 var future; |
| 51 if (multipart.isText) { | 53 if (multipart.isText) { |
| 52 future = multipart | 54 future = multipart |
| 53 .fold(new StringBuffer(), (b, s) => b..write(s)) | 55 .fold(new StringBuffer(), (b, s) => b..write(s)) |
| 54 .then((b) => b.toString()); | 56 .then((b) => b.toString()); |
| 55 } else { | 57 } else { |
| 56 future = multipart | 58 future = multipart |
| 57 .fold([], (b, s) => b..addAll(s)); | 59 .fold([], (b, s) => b..addAll(s)); |
| 58 } | 60 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 postDataTest(message, | 190 postDataTest(message, |
| 189 'multipart/form-data', | 191 'multipart/form-data', |
| 190 '----WebKitFormBoundaryfe0EzV1aNysD1bPh', | 192 '----WebKitFormBoundaryfe0EzV1aNysD1bPh', |
| 191 [new FormField('name', 'øv')]); | 193 [new FormField('name', 'øv')]); |
| 192 } | 194 } |
| 193 | 195 |
| 194 | 196 |
| 195 void main() { | 197 void main() { |
| 196 testPostData(); | 198 testPostData(); |
| 197 } | 199 } |
| OLD | NEW |