diff --git a/lib/src/proxy_layer.dart b/lib/src/proxy_layer.dart index 1ec4992e..1152a46f 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -22,8 +22,9 @@ String _pathify(String path) { /// Copies HTTP headers ;) void copyHeaders(HttpHeaders from, HttpHeaders to) { - from.forEach(to.add); - to + from.forEach(to.set); + + /*to ..chunkedTransferEncoding = from.chunkedTransferEncoding ..contentLength = from.contentLength ..contentType = from.contentType @@ -32,7 +33,7 @@ void copyHeaders(HttpHeaders from, HttpHeaders to) { ..host = from.host ..ifModifiedSince = from.ifModifiedSince ..persistentConnection = from.persistentConnection - ..port = from.port; + ..port = from.port;*/ } class ProxyLayer { @@ -91,17 +92,18 @@ class ProxyLayer { final rq = await _client.open(req.method, host, port, mapping); _printDebug('Opened client request'); - rq.headers - ..set('X-Forwarded-For', req.connectionInfo.remoteAddress.address) - ..set('X-Forwarded-Port', req.connectionInfo.remotePort.toString()) - ..set('X-Forwarded-Host', - req.headers.host ?? req.headers.value(HttpHeaders.HOST) ?? 'none') - ..set('X-Forwarded-Proto', protocol); - _printDebug('Added X-Forwarded headers'); copyHeaders(req.headers, rq.headers); _printDebug('Copied headers'); rq.cookies.addAll(req.cookies ?? []); _printDebug('Added cookies'); + rq.headers + .set('X-Forwarded-For', req.io.connectionInfo.remoteAddress.address); + rq.headers + ..set('X-Forwarded-Port', req.io.connectionInfo.remotePort.toString()) + ..set('X-Forwarded-Host', + req.headers.host ?? req.headers.value(HttpHeaders.HOST) ?? 'none') + ..set('X-Forwarded-Proto', protocol); + _printDebug('Added X-Forwarded headers'); await rq.addStream(req.io); final HttpClientResponse rs = await rq.close(); diff --git a/pubspec.yaml b/pubspec.yaml index 7e6f1ee3..3a09ad81 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: 1.0.0-dev+4 +version: 1.0.0-dev+5 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: diff --git a/test/basic_test.dart b/test/basic_test.dart index e8b13d17..1dcba888 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -15,10 +15,10 @@ main() { app = new Angel(); testServer = await testApp().startServer(); - + await app.configure(new ProxyLayer( testServer.address.address, testServer.port, - publicPath: '/proxy', debug: true)); + publicPath: '/proxy')); await app.configure(new ProxyLayer( testServer.address.address, testServer.port, mapTo: '/foo'));