| 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 import 'dart:convert'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 String toString() { | 43 String toString() { |
| 44 return "FormField('$name', '$value', '$contentType', '$filename')"; | 44 return "FormField('$name', '$value', '$contentType', '$filename')"; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void postDataTest(List<int> message, | 48 void postDataTest(List<int> message, |
| 49 String contentType, | 49 String contentType, |
| 50 String boundary, | 50 String boundary, |
| 51 List<FormField> expectedFields, | 51 List<FormField> expectedFields, |
| 52 {defaultEncoding: LATIN1}) { | 52 {defaultEncoding: LATIN1}) async { |
| 53 HttpServer.bind("127.0.0.1", 0).then((server) { | 53 var addr = (await InternetAddress.lookup("localhost"))[0]; |
| 54 HttpServer.bind(addr, 0).then((server) { |
| 54 server.listen((request) { | 55 server.listen((request) { |
| 55 String boundary = request.headers.contentType.parameters['boundary']; | 56 String boundary = request.headers.contentType.parameters['boundary']; |
| 56 request | 57 request |
| 57 .transform(new MimeMultipartTransformer(boundary)) | 58 .transform(new MimeMultipartTransformer(boundary)) |
| 58 .map((part) => HttpMultipartFormData.parse( | 59 .map((part) => HttpMultipartFormData.parse( |
| 59 part, defaultEncoding: defaultEncoding)) | 60 part, defaultEncoding: defaultEncoding)) |
| 60 .map((multipart) { | 61 .map((multipart) { |
| 61 var future; | 62 var future; |
| 62 if (multipart.isText) { | 63 if (multipart.isText) { |
| 63 future = multipart.join(); | 64 future = multipart.join(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 79 }); | 80 }); |
| 80 }) | 81 }) |
| 81 .toList() | 82 .toList() |
| 82 .then(Future.wait) | 83 .then(Future.wait) |
| 83 .then((fields) { | 84 .then((fields) { |
| 84 expect(fields, equals(expectedFields)); | 85 expect(fields, equals(expectedFields)); |
| 85 request.response.close().then((_) => server.close()); | 86 request.response.close().then((_) => server.close()); |
| 86 }); | 87 }); |
| 87 }); | 88 }); |
| 88 var client = new HttpClient(); | 89 var client = new HttpClient(); |
| 89 client.post('127.0.0.1', server.port, '/') | 90 client.post('localhost', server.port, '/') |
| 90 .then((request) { | 91 .then((request) { |
| 91 request.headers.set('content-type', | 92 request.headers.set('content-type', |
| 92 'multipart/form-data; boundary=$boundary'); | 93 'multipart/form-data; boundary=$boundary'); |
| 93 request.add(message); | 94 request.add(message); |
| 94 return request.close(); | 95 return request.close(); |
| 95 }) | 96 }) |
| 96 .then((response) { | 97 .then((response) { |
| 97 client.close(); | 98 client.close(); |
| 98 }); | 99 }); |
| 99 }); | 100 }); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 'multipart/form-data', | 249 'multipart/form-data', |
| 249 '----WebKitFormBoundaryfe0EzV1aNysD1bPh', | 250 '----WebKitFormBoundaryfe0EzV1aNysD1bPh', |
| 250 [new FormField('name', 'øv')]); | 251 [new FormField('name', 'øv')]); |
| 251 } | 252 } |
| 252 | 253 |
| 253 | 254 |
| 254 void main() { | 255 void main() { |
| 255 testEmptyPostData(); | 256 testEmptyPostData(); |
| 256 testPostData(); | 257 testPostData(); |
| 257 } | 258 } |
| OLD | NEW |