This commit is contained in:
thosakwe 2017-01-11 19:19:15 -05:00
parent 3dcc17c5aa
commit 2613f1db0a
3 changed files with 15 additions and 13 deletions

View file

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

View file

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

View file

@ -18,7 +18,7 @@ main() {
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'));