Fixed!
This commit is contained in:
parent
3dcc17c5aa
commit
2613f1db0a
3 changed files with 15 additions and 13 deletions
|
@ -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();
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in a new issue