Fixed gzipping permanently

This commit is contained in:
thosakwe 2017-04-22 15:00:38 -04:00
parent cfadd31934
commit 3bfec883d2
4 changed files with 15 additions and 9 deletions

View file

@ -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).

View file

@ -140,10 +140,12 @@ 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}');
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) {

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

View file

@ -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 {