From 0b518f36aae89be9bd9847ce94d334ac4dc69972 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Tue, 20 Jun 2017 12:23:10 -0400 Subject: [PATCH] 1.1.1 --- .idea/modules.xml | 8 ++++++++ .idea/shelf.iml | 18 ++++++++++++++++++ .idea/vcs.xml | 6 ++++++ example/dartlang_org.dart | 26 ++++++++++++++++++++++++++ lib/src/convert.dart | 1 + pubspec.yaml | 3 ++- 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .idea/modules.xml create mode 100644 .idea/shelf.iml create mode 100644 .idea/vcs.xml create mode 100644 example/dartlang_org.dart diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..c39dfcd7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/shelf.iml b/.idea/shelf.iml new file mode 100644 index 00000000..02bd9dfb --- /dev/null +++ b/.idea/shelf.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/example/dartlang_org.dart b/example/dartlang_org.dart new file mode 100644 index 00000000..436d6650 --- /dev/null +++ b/example/dartlang_org.dart @@ -0,0 +1,26 @@ +import 'dart:io'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_shelf/angel_shelf.dart'; +import 'package:shelf_proxy/shelf_proxy.dart'; + +main() async { + var app = new Angel(); + + // `shelf` request handler + var shelfHandler = proxyHandler('https://www.dartlang.org'); + + // Use `embedShelf` to adapt a `shelf` handler for use within Angel. + var angelHandler = embedShelf(shelfHandler); + + // A normal Angel route. + app.get('/angel', (req, ResponseContext res) { + res.write('Hooray for `package:angel_shelf`!'); + res.end(); // End execution of handlers, so we don't proxy to dartlang.org when we don't need to. + }); + + // Proxy any other request through to dartlang.org + app.after.add(angelHandler); + + var server = await app.startServer(InternetAddress.LOOPBACK_IP_V4, 8080); + print('Proxying at http://${server.address.host}:${server.port}'); +} diff --git a/lib/src/convert.dart b/lib/src/convert.dart index 22a7ebf1..810555f6 100644 --- a/lib/src/convert.dart +++ b/lib/src/convert.dart @@ -60,6 +60,7 @@ Future mergeShelfResponse( angelResponse.headers.addAll(shelfResponse.headers); angelResponse.statusCode = shelfResponse.statusCode; angelResponse.properties['shelf_context'] = shelfResponse.context; + angelResponse.properties['shelf_response'] = shelfResponse; await shelfResponse.read().forEach(angelResponse.buffer.add); angelResponse.end(); } diff --git a/pubspec.yaml b/pubspec.yaml index 8b5ea860..84c7c7c7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_shelf description: Shelf interop with Angel. -version: 1.1.0 +version: 1.1.1 author: Tobe O homepage: https://github.com/angel-dart/shelf environment: @@ -11,4 +11,5 @@ dependencies: dev_dependencies: angel_diagnostics: ^1.0.0 angel_test: ^1.0.0 + shelf_proxy: ^0.1.0 test: ^0.12.0 \ No newline at end of file