Saturday, 7 September 2013

Dart - How to serve gzip-encoded html page

Dart - How to serve gzip-encoded html page

I'm trying to gzip a .html file and then pipe it to HttpResponse.
import 'dart:io';
void main() {
File f = new File('some_template.html');
HttpServer.bind('localhost', 8080)
.then((HttpServer server) {
server.listen((HttpRequest request) {
HttpResponse response = request.response;
f.openRead()
.transform(GZIP.encoder)
.pipe(response);
});
});
}
No error, but instead of serving the html page, the browser downloads the
compressed html page. Care to give me a hint?

No comments:

Post a Comment