This commit is contained in:
Tobe O 2018-12-09 17:39:11 -05:00
parent 327b3996c1
commit 67303b82aa
6 changed files with 17 additions and 15 deletions

View file

@ -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.

View file

@ -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.

View file

@ -105,8 +105,10 @@ class Proxy {
List<int> body;
if (req.method != 'GET' && req.app.keepRawRequestBuffers == true) {
body = (await req.parse()).originalBuffer;
if (!req.hasParsedBody) {
body = await req.body
.fold<BytesBuilder>(new BytesBuilder(), (bb, buf) => bb..add(buf))
.then((bb) => bb.takeBytes());
}
var rq = new http.Request(req.method, uri);

View file

@ -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 <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/proxy
environment:

View file

@ -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;
});

View file

@ -6,14 +6,12 @@ import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';
Future<HttpServer> 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;
});