This commit is contained in:
thosakwe 2017-04-24 16:46:52 -04:00
parent 19f2e23c6a
commit 918b20086f
4 changed files with 16 additions and 4 deletions

View file

@ -1,6 +1,6 @@
# angel_proxy # angel_proxy
[![version 1.0.5+1](https://img.shields.io/badge/version-1.0.5+1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_proxy) [![version 1.0.6](https://img.shields.io/badge/version-1.0.6-brightgreen.svg)](https://pub.dartlang.org/packages/angel_proxy)
[![build status](https://travis-ci.org/angel-dart/proxy.svg)](https://travis-ci.org/angel-dart/proxy) [![build status](https://travis-ci.org/angel-dart/proxy.svg)](https://travis-ci.org/angel-dart/proxy)
Angel middleware to forward requests to another server (i.e. pub serve). Angel middleware to forward requests to another server (i.e. pub serve).

View file

@ -23,7 +23,9 @@ String _pathify(String path) {
/// Copies HTTP headers ;) /// Copies HTTP headers ;)
void copyHeaders(HttpHeaders from, HttpHeaders to) { void copyHeaders(HttpHeaders from, HttpHeaders to) {
from.forEach((k, v) { from.forEach((k, v) {
if (k != HttpHeaders.CONTENT_ENCODING || !v.contains('gzip')) to.set(k, v); if (k != HttpHeaders.SERVER &&
(k != HttpHeaders.CONTENT_ENCODING || !v.contains('gzip')))
to.set(k, v);
}); });
/*to /*to
@ -42,7 +44,7 @@ class ProxyLayer {
Angel app; Angel app;
HttpClient _client; HttpClient _client;
String _prefix; String _prefix;
final bool debug, streamToIO; final bool debug, recoverFrom404, streamToIO;
final String host, mapTo, publicPath; final String host, mapTo, publicPath;
final int port; final int port;
final String protocol; final String protocol;
@ -52,6 +54,7 @@ class ProxyLayer {
this.mapTo: '/', this.mapTo: '/',
this.publicPath: '/', this.publicPath: '/',
this.protocol: 'http', this.protocol: 'http',
this.recoverFrom404: true,
this.streamToIO: false, this.streamToIO: false,
SecurityContext securityContext}) { SecurityContext securityContext}) {
_client = new HttpClient(context: securityContext); _client = new HttpClient(context: securityContext);
@ -114,6 +117,8 @@ class ProxyLayer {
_printDebug( _printDebug(
'Proxy responded to $mapping with status code ${rs.statusCode}'); 'Proxy responded to $mapping with status code ${rs.statusCode}');
if (rs.statusCode == 404 && recoverFrom404 != false) return true;
res res
..statusCode = rs.statusCode ..statusCode = rs.statusCode
..contentType = rs.headers.contentType; ..contentType = rs.headers.contentType;
@ -126,6 +131,11 @@ class ProxyLayer {
..end(); ..end();
copyHeaders(rs.headers, res.io.headers); copyHeaders(rs.headers, res.io.headers);
res.io.statusCode = rs.statusCode;
if (rs.headers.contentType != null)
res.io.headers.contentType = rs.headers.contentType;
_printDebug('Outgoing content length: ${res.io.contentLength}'); _printDebug('Outgoing content length: ${res.io.contentLength}');
if (rs.headers[HttpHeaders.CONTENT_ENCODING]?.contains('gzip') == true) { if (rs.headers[HttpHeaders.CONTENT_ENCODING]?.contains('gzip') == true) {

View file

@ -4,6 +4,7 @@ import 'proxy_layer.dart';
class PubServeLayer extends ProxyLayer { class PubServeLayer extends ProxyLayer {
PubServeLayer( PubServeLayer(
{bool debug: false, {bool debug: false,
bool recoverFrom404: true,
bool streamToIO: true, bool streamToIO: true,
String host: 'localhost', String host: 'localhost',
String mapTo: '/', String mapTo: '/',
@ -15,6 +16,7 @@ class PubServeLayer extends ProxyLayer {
mapTo: mapTo, mapTo: mapTo,
protocol: protocol, protocol: protocol,
publicPath: publicPath, publicPath: publicPath,
recoverFrom404: recoverFrom404 != false,
streamToIO: streamToIO != false); streamToIO: streamToIO != false);
@override @override

View file

@ -1,6 +1,6 @@
name: angel_proxy name: angel_proxy
description: Angel middleware to forward requests to another server (i.e. pub serve). description: Angel middleware to forward requests to another server (i.e. pub serve).
version: 1.0.5+1 version: 1.0.6
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/proxy homepage: https://github.com/angel-dart/proxy
environment: environment: