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

Unified Diff: lib/shelf_pubserver.dart

Issue 930513002: Added README, a bin/serve example server which can be used locally. (Closed) Base URL: https://github.com/dart-lang/pub_server.git@master
Patch Set: Moved to old-style async due to another mimepart stream issue, small bugfix' Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « example/src/examples/http_proxy_repository.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/shelf_pubserver.dart
diff --git a/lib/shelf_pubserver.dart b/lib/shelf_pubserver.dart
index 16f4f5553be423a66241da1ec04847ea9f1fd885..1235126f3cd4a0bde55e30c11bec9cfc88ca25d5 100644
--- a/lib/shelf_pubserver.dart
+++ b/lib/shelf_pubserver.dart
@@ -308,19 +308,39 @@ class ShelfPubServer {
var match = _boundaryRegExp.matchAsPrefix(contentType);
if (match != null) {
var boundary = match.group(1);
- return stream
- .transform(new MimeMultipartTransformer(boundary))
- .first.then((MimeMultipart part) {
+
+ // We have to listen to all multiparts: Just doing `parts.first` will
+ // result in the cancelation of the subscription which causes
+ // eventually a destruction of the socket, this is an odd side-effect.
+ // What we would like to have is something like this:
+ // parts.expect(1).then((part) { upload(part); })
+ bool firstPartArrived = false;
+ var completer = new Completer();
+ var subscription;
+
+ var parts = stream.transform(new MimeMultipartTransformer(boundary));
+ subscription = parts.listen((MimeMultipart part) {
+ // If we get more than one part, we'll ignore the rest of the input.
+ if (firstPartArrived) {
+ subscription.cancel();
+ return;
+ }
+ firstPartArrived = true;
+
// TODO: Ensure that `part.headers['content-disposition']` is
// `form-data; name="file"; filename="package.tar.gz`
- return repository.upload(part).then((_) {
+ repository.upload(part).then((_) {
+ _logger.info('Redirecting to found url.');
return new shelf.Response.found(_finishUploadSimpleUrl(uri));
}).catchError((error, stack) {
+ _logger.warning('Error occured: $error\n$stack.');
// TODO: Do error checking and return error codes?
return new shelf.Response.found(
_finishUploadSimpleUrl(uri, error: error));
- });
+ }).then(completer.complete);
});
+
+ return completer.future;
}
}
return
« no previous file with comments | « example/src/examples/http_proxy_repository.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698