diff --git a/README.md b/README.md index 1f5c074c..70d189f7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_proxy -[![version 1.0.4](https://img.shields.io/badge/version-1.0.4-brightgreen.svg)](https://pub.dartlang.org/packages/angel_proxy) +[![version 1.0.5](https://img.shields.io/badge/version-1.0.5-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 c171c19a..a313a39b 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -140,11 +140,13 @@ class ProxyLayer { ..persistentConnection = from.persistentConnection ..port = from.port; - if (rs.headers[HttpHeaders.CONTENT_ENCODING] != null) - res.io.headers.set(HttpHeaders.CONTENT_ENCODING, - rs.headers[HttpHeaders.CONTENT_ENCODING]); + _printDebug('Outgoing content length: ${res.io.contentLength}'); - await rs.pipe(res.io); + if (rs.headers[HttpHeaders.CONTENT_ENCODING]?.contains('gzip') == true) { + res.io.headers.set(HttpHeaders.CONTENT_ENCODING, 'gzip'); + await rs.transform(GZIP.encoder).pipe(res.io); + } else + await rs.pipe(res.io); } else { rs.headers.forEach((k, v) { if (k != HttpHeaders.CONTENT_ENCODING || !v.contains('gzip')) diff --git a/pubspec.yaml b/pubspec.yaml index e34b7941..5f3d05cf 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.4 +version: 1.0.5 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: diff --git a/test/pub_serve_test.dart b/test/pub_serve_test.dart index 955b89e5..36fdf5b5 100644 --- a/test/pub_serve_test.dart +++ b/test/pub_serve_test.dart @@ -20,7 +20,7 @@ main() { app = new Angel(); app.get('/bar', (req, res) => res.write('normal')); var layer = new PubServeLayer( - publicPath: '/proxy', host: server.address.address, port: server.port); + debug: true, publicPath: '/proxy', host: server.address.address, port: server.port); print('streamToIO: ${layer.streamToIO}'); await app.configure(layer); @@ -49,7 +49,9 @@ main() { expect(response, hasHeader('content-encoding', 'gzip')); // Should have gzipped body - expect(response.body, 'pub serve'); + // + // We have to decode it, because `mock_request` does not auto-decode. + expect(UTF8.decode(GZIP.decode(response.bodyBytes)), 'pub serve'); }); test('empty', () async { @@ -59,7 +61,9 @@ main() { expect(response, hasHeader('content-encoding', 'gzip')); // Should have gzipped body - expect(response.bodyBytes, isEmpty); + // + // We have to decode it, because `mock_request` does not auto-decode. + expect(UTF8.decode(GZIP.decode(response.bodyBytes)), isEmpty); }); test('normal', () async {