From 918b20086fefd748acf895cf8d2dcbcc2f33652f Mon Sep 17 00:00:00 2001 From: thosakwe Date: Mon, 24 Apr 2017 16:46:52 -0400 Subject: [PATCH] 1.0.6 --- README.md | 2 +- lib/src/proxy_layer.dart | 14 ++++++++++++-- lib/src/pub_serve_layer.dart | 2 ++ pubspec.yaml | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 16d081a3..c7c66755 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/src/proxy_layer.dart b/lib/src/proxy_layer.dart index 895ff8a2..0460d69a 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -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) { diff --git a/lib/src/pub_serve_layer.dart b/lib/src/pub_serve_layer.dart index bb36f850..876edcfa 100644 --- a/lib/src/pub_serve_layer.dart +++ b/lib/src/pub_serve_layer.dart @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index 8b9e1a8c..3b147246 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.5+1 +version: 1.0.6 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: