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
[![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)
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 ;)
void copyHeaders(HttpHeaders from, HttpHeaders to) {
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
@ -42,7 +44,7 @@ class ProxyLayer {
Angel app;
HttpClient _client;
String _prefix;
final bool debug, streamToIO;
final bool debug, recoverFrom404, streamToIO;
final String host, mapTo, publicPath;
final int port;
final String protocol;
@ -52,6 +54,7 @@ class ProxyLayer {
this.mapTo: '/',
this.publicPath: '/',
this.protocol: 'http',
this.recoverFrom404: true,
this.streamToIO: false,
SecurityContext securityContext}) {
_client = new HttpClient(context: securityContext);
@ -114,6 +117,8 @@ class ProxyLayer {
_printDebug(
'Proxy responded to $mapping with status code ${rs.statusCode}');
if (rs.statusCode == 404 && recoverFrom404 != false) return true;
res
..statusCode = rs.statusCode
..contentType = rs.headers.contentType;
@ -126,6 +131,11 @@ class ProxyLayer {
..end();
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}');
if (rs.headers[HttpHeaders.CONTENT_ENCODING]?.contains('gzip') == true) {

View file

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

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.5+1
version: 1.0.6
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/proxy
environment: