Add gzip compression support
I discovered that my server wasn't respecting autoCompress = true because this http_server package adds its own content-length headers. See what @sgjesse said here:
https://github.com/dart-lang/sdk/issues/23350#issuecomment-108464543
Can we add support? I imagine many folks use this package with their servers and want to gzip.
Have you seen shelf and shelf_static?
https://pub.dartlang.org/packages/shelf
https://pub.dartlang.org/packages/shelf_static
@kevmoo is there something we can recommend for gzip + shelf?
This shouldn't be a problem with shelf. Just provide your own instance.
http://www.dartdocs.org/documentation/shelf/0.6.3+1/shelf.io/serveRequests.html
Thanks for the help. Finally done refactoring for Shelf. Alas, still doesn't gzip.
io.serve(_handler, address, port).then((server) {
server.autoCompress = true;
server.sessionTimeout = new DateTime.now()
.add(new Duration(days: 365))
.toUtc()
.millisecondsSinceEpoch *
1000;
print('Serving at http://${server.address.host}:${server.port}');
});
Ok, got it working. I had to set chunked transfer-encoding in the headers. So I change the Response wherever I return files, e.g.:
Future<shelf.Response> _handleFile(shelf.Request request) async {
shelf.Response response = await this.staticHandler(request);
response = response.change(headers: {'Transfer-Encoding': 'chunked'});
return response;
}
Voila: http://d.pr/i/Iaco (p.s. nice plug there)