| Index: tests/standalone/io/http_body_test.dart
|
| diff --git a/tests/standalone/io/http_body_test.dart b/tests/standalone/io/http_body_test.dart
|
| index cd1c4b5260d94e5ed762ce2a840369bbba8e766b..a7a5b99ba4b31f1cdab419d168d0257422b4817a 100644
|
| --- a/tests/standalone/io/http_body_test.dart
|
| +++ b/tests/standalone/io/http_body_test.dart
|
| @@ -90,7 +90,7 @@ void testHttpServerRequestBody() {
|
| List<int> content,
|
| dynamic expectedBody,
|
| String type,
|
| - [bool shouldFail = false]) {
|
| + {bool shouldFail: false}) {
|
| HttpServer.bind("127.0.0.1", 0).then((server) {
|
| server.transform(new HttpBodyHandler())
|
| .listen((body) {
|
| @@ -98,26 +98,49 @@ void testHttpServerRequestBody() {
|
| Expect.equals(type, body.type);
|
| switch (type) {
|
| case "text":
|
| - Expect.equals(body.mimeType, "text/plain");
|
| + Expect.equals(body.contentType.mimeType, "text/plain");
|
| Expect.equals(expectedBody, body.body);
|
| break;
|
|
|
| case "json":
|
| - Expect.equals(body.mimeType, "application/json");
|
| + Expect.equals(body.contentType.mimeType, "application/json");
|
| Expect.mapEquals(expectedBody, body.body);
|
| break;
|
|
|
| case "binary":
|
| - Expect.equals(body.mimeType, null);
|
| + Expect.equals(body.contentType, null);
|
| Expect.listEquals(expectedBody, body.body);
|
| break;
|
|
|
| + case "form":
|
| + Expect.equals(body.contentType.mimeType, 'multipart/form-data');
|
| + Expect.setEquals(expectedBody.keys.toSet(),
|
| + body.body.keys.toSet());
|
| + for (var key in expectedBody.keys) {
|
| + if (body.body[key] is HttpBodyFileUpload) {
|
| + Expect.equals(expectedBody[key]['contentType'],
|
| + body.body[key].contentType.toString());
|
| + Expect.equals(expectedBody[key]['filename'],
|
| + body.body[key].filename);
|
| + if (body.body[key].content is String) {
|
| + Expect.equals(expectedBody[key]['content'],
|
| + body.body[key].content);
|
| + } else {
|
| + Expect.listEquals(expectedBody[key]['content'],
|
| + body.body[key].content);
|
| + }
|
| + } else {
|
| + Expect.equals(expectedBody[key], body.body[key]);
|
| + }
|
| + }
|
| + break;
|
| +
|
| default:
|
| Expect.fail("bad body type");
|
| }
|
| body.response.close();
|
| }, onError: (error) {
|
| - if (!shouldFail) Expect.fail("Error unexpected");
|
| + if (!shouldFail) throw error;
|
| });
|
|
|
| var client = new HttpClient();
|
| @@ -160,9 +183,63 @@ void testHttpServerRequestBody() {
|
| '{ bad json }'.codeUnits,
|
| null,
|
| "json",
|
| - true);
|
| + shouldFail: true);
|
|
|
| test(null, "body".codeUnits, "body".codeUnits, "binary");
|
| +
|
| + test("multipart/form-data; boundary=AaB03x",
|
| + '''
|
| +--AaB03x\r
|
| +Content-Disposition: form-data; name="name"\r
|
| +\r
|
| +Larry\r
|
| +--AaB03x--\r\n'''.codeUnits,
|
| + { "name": "Larry" },
|
| + "form");
|
| +
|
| + test("multipart/form-data; boundary=AaB03x",
|
| + '''
|
| +--AaB03x\r
|
| +Content-Disposition: form-data; name="files"; filename="myfile"\r
|
| +Content-Type: application/octet-stream\r
|
| +\r
|
| +File content\r
|
| +--AaB03x--\r\n'''.codeUnits,
|
| + { "files": { 'filename': 'myfile',
|
| + 'contentType': 'application/octet-stream',
|
| + 'content': 'File content'.codeUnits} },
|
| + "form");
|
| +
|
| + test("multipart/form-data; boundary=AaB03x",
|
| + '''
|
| +--AaB03x\r
|
| +Content-Disposition: form-data; name="files"; filename="myfile"\r
|
| +Content-Type: application/octet-stream\r
|
| +\r
|
| +File content\r
|
| +--AaB03x\r
|
| +Content-Disposition: form-data; name="files"; filename="myfile"\r
|
| +Content-Type: text/plain\r
|
| +\r
|
| +File content\r
|
| +--AaB03x--\r\n'''.codeUnits,
|
| + { "files": { 'filename': 'myfile',
|
| + 'contentType': 'text/plain',
|
| + 'content': 'File content'} },
|
| + "form");
|
| +
|
| + test("multipart/form-data; boundary=AaB03x",
|
| + '''
|
| +--AaB03x\r
|
| +Content-Disposition: form-data; name="files"; filename="myfile"\r
|
| +Content-Type: application/json\r
|
| +\r
|
| +File content\r
|
| +--AaB03x--\r\n'''.codeUnits,
|
| + { "files": { 'filename': 'myfile',
|
| + 'contentType': 'application/json',
|
| + 'content': 'File content'} },
|
| + "form");
|
| }
|
|
|
| void main() {
|
|
|