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

Side by Side Diff: utils/tests/pub/pub_lish_test.dart

Issue 12211052: Drain HTTP request input streams before responding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « utils/pub/io.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 pub_lish_test; 5 library pub_lish_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json' as json; 8 import 'dart:json' as json;
9 9
10 import 'test_pub.dart'; 10 import 'test_pub.dart';
(...skipping 20 matching lines...) Expand all
31 response.outputStream.writeString(json.stringify(body)); 31 response.outputStream.writeString(json.stringify(body));
32 response.outputStream.close(); 32 response.outputStream.close();
33 }); 33 });
34 }); 34 });
35 } 35 }
36 36
37 void handleUpload(ScheduledServer server) { 37 void handleUpload(ScheduledServer server) {
38 server.handle('POST', '/upload', (request, response) { 38 server.handle('POST', '/upload', (request, response) {
39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate 39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
40 // that the request body is correctly formatted. See issue 6952. 40 // that the request body is correctly formatted. See issue 6952.
41 return server.url.then((url) { 41 return drainInputStream(request.inputStream).then((_) {
42 return server.url;
nweiz 2013/02/06 20:47:05 Style nit: I'd probably make this a "=>"-style lam
Bob Nystrom 2013/02/06 20:50:40 I did that first, but then the following then() do
43 }).then((url) {
42 response.statusCode = 302; 44 response.statusCode = 302;
43 response.headers.set('location', url.resolve('/create').toString()); 45 response.headers.set('location', url.resolve('/create').toString());
44 response.outputStream.close(); 46 response.outputStream.close();
45 }); 47 });
46 }); 48 });
47 } 49 }
48 50
49 main() { 51 main() {
50 initConfig(); 52 initConfig();
51 setUp(() => normalPackage.scheduleCreate()); 53 setUp(() => normalPackage.scheduleCreate());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 255
254 integration('cloud storage upload provides an error', () { 256 integration('cloud storage upload provides an error', () {
255 var server = new ScheduledServer(); 257 var server = new ScheduledServer();
256 credentialsFile(server, 'access token').scheduleCreate(); 258 credentialsFile(server, 'access token').scheduleCreate();
257 var pub = startPubLish(server); 259 var pub = startPubLish(server);
258 260
259 confirmPublish(pub); 261 confirmPublish(pub);
260 handleUploadForm(server); 262 handleUploadForm(server);
261 263
262 server.handle('POST', '/upload', (request, response) { 264 server.handle('POST', '/upload', (request, response) {
263 response.statusCode = 400; 265 return drainInputStream(request.inputStream).then((_) {
264 response.headers.contentType = new ContentType('application', 'xml'); 266 response.statusCode = 400;
265 response.outputStream.writeString('<Error><Message>Your request sucked.' 267 response.headers.contentType = new ContentType('application', 'xml');
266 '</Message></Error>'); 268 response.outputStream.writeString('<Error><Message>Your request sucked.'
267 response.outputStream.close(); 269 '</Message></Error>');
270 response.outputStream.close();
271 });
268 }); 272 });
269 273
270 // TODO(nweiz): This should use the server's error message once the client 274 // TODO(nweiz): This should use the server's error message once the client
271 // can parse the XML. 275 // can parse the XML.
272 expectLater(pub.nextErrLine(), equals('Failed to upload the package.')); 276 expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
273 pub.shouldExit(1); 277 pub.shouldExit(1);
274 }); 278 });
275 279
276 integration("cloud storage upload doesn't redirect", () { 280 integration("cloud storage upload doesn't redirect", () {
277 var server = new ScheduledServer(); 281 var server = new ScheduledServer();
278 credentialsFile(server, 'access token').scheduleCreate(); 282 credentialsFile(server, 'access token').scheduleCreate();
279 var pub = startPubLish(server); 283 var pub = startPubLish(server);
280 284
281 confirmPublish(pub); 285 confirmPublish(pub);
282 handleUploadForm(server); 286 handleUploadForm(server);
283 287
284 server.handle('POST', '/upload', (request, response) { 288 server.handle('POST', '/upload', (request, response) {
285 // don't set the location header 289 return drainInputStream(request.inputStream).then((_) {
286 response.outputStream.close(); 290 // Don't set the location header.
291 response.outputStream.close();
292 });
287 }); 293 });
288 294
289 expectLater(pub.nextErrLine(), equals('Failed to upload the package.')); 295 expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
290 pub.shouldExit(1); 296 pub.shouldExit(1);
291 }); 297 });
292 298
293 integration('package creation provides an error', () { 299 integration('package creation provides an error', () {
294 var server = new ScheduledServer(); 300 var server = new ScheduledServer();
295 credentialsFile(server, 'access token').scheduleCreate(); 301 credentialsFile(server, 'access token').scheduleCreate();
296 var pub = startPubLish(server); 302 var pub = startPubLish(server);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 server.handle('GET', '/create', (request, response) { 370 server.handle('GET', '/create', (request, response) {
365 response.outputStream.writeString(json.stringify(body)); 371 response.outputStream.writeString(json.stringify(body));
366 response.outputStream.close(); 372 response.outputStream.close();
367 }); 373 });
368 374
369 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 375 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
370 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 376 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
371 pub.shouldExit(1); 377 pub.shouldExit(1);
372 }); 378 });
373 } 379 }
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698