Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: pkg/http_server/test/http_body_test.dart

Issue 31813002: Expose the HttpRequest object in HttpRequestBody, making all request properties available. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'dart:io'; 5 import 'dart:io';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:http_server/http_server.dart'; 8 import 'package:http_server/http_server.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 String type, 87 String type,
88 {bool shouldFail: false, 88 {bool shouldFail: false,
89 Encoding defaultEncoding: UTF8}) { 89 Encoding defaultEncoding: UTF8}) {
90 HttpServer.bind("127.0.0.1", 0).then((server) { 90 HttpServer.bind("127.0.0.1", 0).then((server) {
91 server.transform(new HttpBodyHandler(defaultEncoding: defaultEncoding)) 91 server.transform(new HttpBodyHandler(defaultEncoding: defaultEncoding))
92 .listen((body) { 92 .listen((body) {
93 expect(shouldFail, isFalse); 93 expect(shouldFail, isFalse);
94 expect(body.type, equals(type)); 94 expect(body.type, equals(type));
95 switch (type) { 95 switch (type) {
96 case "text": 96 case "text":
97 expect(body.contentType.mimeType, equals("text/plain")); 97 expect(body.request.headers.contentType.mimeType,
98 equals("text/plain"));
98 expect(body.body, equals(expectedBody)); 99 expect(body.body, equals(expectedBody));
99 break; 100 break;
100 101
101 case "json": 102 case "json":
102 expect(body.contentType.mimeType, equals("application/json")); 103 expect(body.request.headers.contentType.mimeType,
104 equals("application/json"));
103 expect(body.body, equals(expectedBody)); 105 expect(body.body, equals(expectedBody));
104 break; 106 break;
105 107
106 case "binary": 108 case "binary":
107 expect(body.contentType, isNull); 109 expect(body.request.headers.contentType, isNull);
108 expect(body.body, equals(expectedBody)); 110 expect(body.body, equals(expectedBody));
109 break; 111 break;
110 112
111 case "form": 113 case "form":
112 var mimeType = body.contentType.mimeType; 114 var mimeType = body.request.headers.contentType.mimeType;
113 expect(mimeType, 115 expect(mimeType,
114 anyOf(equals('multipart/form-data'), 116 anyOf(equals('multipart/form-data'),
115 equals('application/x-www-form-urlencoded'))); 117 equals('application/x-www-form-urlencoded')));
116 expect(body.body.keys.toSet(), 118 expect(body.body.keys.toSet(),
117 equals(expectedBody.keys.toSet())); 119 equals(expectedBody.keys.toSet()));
118 for (var key in expectedBody.keys) { 120 for (var key in expectedBody.keys) {
119 var found = body.body[key]; 121 var found = body.body[key];
120 var expected = expectedBody[key]; 122 var expected = expectedBody[key];
121 if (found is HttpBodyFileUpload) { 123 if (found is HttpBodyFileUpload) {
122 expect(found.contentType.toString(), 124 expect(found.contentType.toString(),
123 equals(expected['contentType'])); 125 equals(expected['contentType']));
124 expect(found.filename, 126 expect(found.filename,
125 equals(expected['filename'])); 127 equals(expected['filename']));
126 expect(found.content, 128 expect(found.content,
127 equals(expected['content'])); 129 equals(expected['content']));
128 } else { 130 } else {
129 expect(found, equals(expected)); 131 expect(found, equals(expected));
130 } 132 }
131 } 133 }
132 break; 134 break;
133 135
134 default: 136 default:
135 throw "bad body type"; 137 throw "bad body type";
136 } 138 }
137 body.response.close(); 139 body.request.response.close();
138 }, onError: (error) { 140 }, onError: (error) {
139 if (!shouldFail) throw error; 141 if (!shouldFail) throw error;
140 }); 142 });
141 143
142 var client = new HttpClient(); 144 var client = new HttpClient();
143 client.post("127.0.0.1", server.port, "/") 145 client.post("127.0.0.1", server.port, "/")
144 .then((request) { 146 .then((request) {
145 if (mimeType != null) { 147 if (mimeType != null) {
146 request.headers.contentType = 148 request.headers.contentType =
147 ContentType.parse(mimeType); 149 ContentType.parse(mimeType);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 test('application/x-www-form-urlencoded', 326 test('application/x-www-form-urlencoded',
325 'name=%C8%A4%C8%A4'.codeUnits, 327 'name=%C8%A4%C8%A4'.codeUnits,
326 { 'name' : 'ȤȤ' }, 328 { 'name' : 'ȤȤ' },
327 "form"); 329 "form");
328 } 330 }
329 331
330 void main() { 332 void main() {
331 testHttpClientResponseBody(); 333 testHttpClientResponseBody();
332 testHttpServerRequestBody(); 334 testHttpServerRequestBody();
333 } 335 }
OLDNEW
« pkg/http_server/lib/src/http_body.dart ('K') | « pkg/http_server/lib/src/http_body_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698