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

Side by Side Diff: pkg/shelf/test/shelf_io_test.dart

Issue 260933004: Support Request hijacking in Shelf, using a similar API to Rack. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 shelf_io_test; 5 library shelf_io_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return syncHandler(request); 178 return syncHandler(request);
179 }); 179 });
180 }); 180 });
181 181
182 return _schedulePost(body: 'test body').then((response) { 182 return _schedulePost(body: 'test body').then((response) {
183 expect(response.statusCode, HttpStatus.OK); 183 expect(response.statusCode, HttpStatus.OK);
184 expect(response.stream.bytesToString(), completion('Hello from /')); 184 expect(response.stream.bytesToString(), completion('Hello from /'));
185 }); 185 });
186 }); 186 });
187 187
188 test('supports request hijacking', () {
189 _scheduleServer((request) {
190 expect(request.method, 'POST');
191
192 request.hijack(expectAsync((stream, sink) {
193 expect(stream.first, completion(equals("Hello".codeUnits)));
194
195 sink.add((
196 "HTTP/1.1 404 Not Found\r\n"
197 "Date: Mon, 23 May 2005 22:38:34 GMT\r\n"
198 "Content-Length: 13\r\n"
199 "\r\n"
200 "Hello, world!").codeUnits);
201 sink.close();
202 }));
203 });
204
205 return _schedulePost(body: "Hello").then((response) {
206 expect(response.statusCode, HttpStatus.NOT_FOUND);
207 expect(response.headers["date"], "Mon, 23 May 2005 22:38:34 GMT");
208 expect(response.stream.bytesToString(),
209 completion(equals("Hello, world!")));
210 });
211 });
212
213 test('reports an error if a HijackException is thrown without hijacking', () {
214 _scheduleServer((request) => throw const HijackException());
215
216 return _scheduleGet().then((response) {
217 expect(response.statusCode, HttpStatus.INTERNAL_SERVER_ERROR);
218 });
219 });
220
188 test('passes asynchronous exceptions to the parent error zone', () { 221 test('passes asynchronous exceptions to the parent error zone', () {
189 return runZoned(() { 222 return runZoned(() {
190 return shelf_io.serve((request) { 223 return shelf_io.serve((request) {
191 new Future(() => throw 'oh no'); 224 new Future(() => throw 'oh no');
192 return syncHandler(request); 225 return syncHandler(request);
193 }, 'localhost', 0).then((server) { 226 }, 'localhost', 0).then((server) {
194 return http.get('http://localhost:${server.port}').then((response) { 227 return http.get('http://localhost:${server.port}').then((response) {
195 expect(response.statusCode, HttpStatus.OK); 228 expect(response.statusCode, HttpStatus.OK);
196 expect(response.body, 'Hello from /'); 229 expect(response.body, 'Hello from /');
197 server.close(); 230 server.close();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 278
246 var request = new http.Request('POST', 279 var request = new http.Request('POST',
247 Uri.parse('http://localhost:$_serverPort/')); 280 Uri.parse('http://localhost:$_serverPort/'));
248 281
249 if (headers != null) request.headers.addAll(headers); 282 if (headers != null) request.headers.addAll(headers);
250 if (body != null) request.body = body; 283 if (body != null) request.body = body;
251 284
252 return request.send(); 285 return request.send();
253 }); 286 });
254 } 287 }
OLDNEW
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698