diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f6ffc30..1babb6a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.1.1 +* Update for framework@2.0.0-alpha.15 + # 2.1.0 - Use `Uri` instead of archaic `host`, `port`, and `mapTo`. Also cleaner + safer + easier. diff --git a/README.md b/README.md index 5d46bdbb..d1ece3b4 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,6 @@ Also, you can map requests to a root path on the remote server: Proxy(client, baseUrl.replace(path: '/path')); ``` -If your app's `keepRawRequestBuffers` is `true`, then request bodies will be forwarded -as well, if they are not empty. This allows things like POST requests to function. +Request bodies will be forwarded as well, if they are not empty. This allows things like POST requests to function. + +For a request body to be forwarded, the body must not have already been parsed. \ No newline at end of file diff --git a/lib/src/proxy_layer.dart b/lib/src/proxy_layer.dart index 43bb6a54..5b4b7090 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -105,8 +105,10 @@ class Proxy { List body; - if (req.method != 'GET' && req.app.keepRawRequestBuffers == true) { - body = (await req.parse()).originalBuffer; + if (!req.hasParsedBody) { + body = await req.body + .fold(new BytesBuilder(), (bb, buf) => bb..add(buf)) + .then((bb) => bb.takeBytes()); } var rq = new http.Request(req.method, uri); diff --git a/pubspec.yaml b/pubspec.yaml index e1232d7a..57b27905 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_proxy description: Angel middleware to forward requests to another server (i.e. pub serve). -version: 2.1.0 +version: 2.1.1 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: diff --git a/test/basic_test.dart b/test/basic_test.dart index ca523d88..46973e63 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -15,7 +15,7 @@ main() { String url; setUp(() async { - app = new Angel()..keepRawRequestBuffers = true; + app = new Angel(); var appHttp = AngelHttp(app); var httpClient = new http.IOClient(); @@ -55,14 +55,12 @@ main() { }); await appHttp.startServer(); - - server = appHttp.httpServer; - url = 'http://${server.address.address}:${server.port}'; + url = appHttp.uri.toString(); }); tearDown(() async { - await testServer.close(force: true); - await server.close(force: true); + await testServer?.close(force: true); + await server?.close(force: true); app = null; url = null; }); diff --git a/test/common.dart b/test/common.dart index 0b775011..86f0df50 100644 --- a/test/common.dart +++ b/test/common.dart @@ -6,14 +6,12 @@ import 'package:angel_framework/http.dart'; import 'package:logging/logging.dart'; Future startTestServer() { - final app = new Angel() - ..eagerParseRequestBodies = false - ..keepRawRequestBuffers = true; + final app = new Angel(); app.get('/hello', (req, res) => res.write('world')); app.get('/foo/bar', (req, res) => res.write('baz')); app.post('/body', (RequestContext req, res) async { - var body = await req.parseBody(); + var body = await req.parseBody().then((_) => req.bodyAsMap); app.logger.info('Body: $body'); return body; });