Drop an unnecessary utility (#16)
This function had unnecessary complexity because it took optional
arguments that were never passed. The entire behavior can also be
written with a short enough pattern that it isn't worthwhile to have a
separate function for it.
diff --git a/lib/shelf_proxy.dart b/lib/shelf_proxy.dart
index 36e7e57..a59623d 100644
--- a/lib/shelf_proxy.dart
+++ b/lib/shelf_proxy.dart
@@ -7,8 +7,6 @@
import 'package:pedantic/pedantic.dart';
import 'package:shelf/shelf.dart';
-import 'src/utils.dart';
-
/// A handler that proxies requests to [url].
///
/// To generate the proxy request, this concatenates [url] and [Request.url].
@@ -51,7 +49,11 @@
_addHeader(clientRequest.headers, 'via',
'${serverRequest.protocolVersion} $proxyName');
- unawaited(store(serverRequest.read(), clientRequest.sink));
+ unawaited(serverRequest
+ .read()
+ .forEach(clientRequest.sink.add)
+ .catchError(clientRequest.sink.addError)
+ .whenComplete(clientRequest.sink.close));
var clientResponse = await client.send(clientRequest);
// Add a Via header. See
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.45
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
deleted file mode 100644
index 79aed49..0000000
--- a/lib/src/utils.dart
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:async';
-
-// TODO(nweiz): remove this when issue 7786 is fixed.
-/// Pipes all data and errors from [stream] into [sink].
-///
-/// When [stream] is done, the returned [Future] is completed and [sink] is
-/// closed if [closeSink] is true.
-///
-/// When an error occurs on [stream], that error is passed to [sink]. If
-/// [cancelOnError] is true, [Future] will be completed successfully and no
-/// more data or errors will be piped from [stream] to [sink]. If
-/// [cancelOnError] and [closeSink] are both true, [sink] will then be
-/// closed.
-Future store(Stream stream, EventSink sink,
- {bool cancelOnError = true, bool closeSink = true}) {
- var completer = Completer();
- stream.listen(sink.add, onError: (e, StackTrace stackTrace) {
- sink.addError(e, stackTrace);
- if (cancelOnError) {
- completer.complete();
- if (closeSink) sink.close();
- }
- }, onDone: () {
- if (closeSink) sink.close();
- completer.complete();
- }, cancelOnError: cancelOnError);
- return completer.future;
-}