Fixed gzipping permanently
This commit is contained in:
parent
cfadd31934
commit
3bfec883d2
4 changed files with 15 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_proxy
|
# 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)
|
[![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).
|
||||||
|
|
|
@ -140,10 +140,12 @@ class ProxyLayer {
|
||||||
..persistentConnection = from.persistentConnection
|
..persistentConnection = from.persistentConnection
|
||||||
..port = from.port;
|
..port = from.port;
|
||||||
|
|
||||||
if (rs.headers[HttpHeaders.CONTENT_ENCODING] != null)
|
_printDebug('Outgoing content length: ${res.io.contentLength}');
|
||||||
res.io.headers.set(HttpHeaders.CONTENT_ENCODING,
|
|
||||||
rs.headers[HttpHeaders.CONTENT_ENCODING]);
|
|
||||||
|
|
||||||
|
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);
|
await rs.pipe(res.io);
|
||||||
} else {
|
} else {
|
||||||
rs.headers.forEach((k, v) {
|
rs.headers.forEach((k, v) {
|
||||||
|
|
|
@ -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.4
|
version: 1.0.5
|
||||||
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:
|
||||||
|
|
|
@ -20,7 +20,7 @@ main() {
|
||||||
app = new Angel();
|
app = new Angel();
|
||||||
app.get('/bar', (req, res) => res.write('normal'));
|
app.get('/bar', (req, res) => res.write('normal'));
|
||||||
var layer = new PubServeLayer(
|
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}');
|
print('streamToIO: ${layer.streamToIO}');
|
||||||
await app.configure(layer);
|
await app.configure(layer);
|
||||||
|
|
||||||
|
@ -49,7 +49,9 @@ main() {
|
||||||
expect(response, hasHeader('content-encoding', 'gzip'));
|
expect(response, hasHeader('content-encoding', 'gzip'));
|
||||||
|
|
||||||
// Should have gzipped body
|
// 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 {
|
test('empty', () async {
|
||||||
|
@ -59,7 +61,9 @@ main() {
|
||||||
expect(response, hasHeader('content-encoding', 'gzip'));
|
expect(response, hasHeader('content-encoding', 'gzip'));
|
||||||
|
|
||||||
// Should have gzipped body
|
// 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 {
|
test('normal', () async {
|
||||||
|
|
Loading…
Reference in a new issue