Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Add gzip compression support #30

Open
davenotik opened this issue Oct 22, 2015 · 4 comments
Open

Add gzip compression support #30

davenotik opened this issue Oct 22, 2015 · 4 comments
Labels

Comments

@davenotik
Copy link

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:

dart-lang/sdk#23350 (comment)

Can we add support? I imagine many folks use this package with their servers and want to gzip.

@sethladd
Copy link
Contributor

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?

@kevmoo kevmoo added the bug label Oct 22, 2015
@kevmoo
Copy link
Contributor

kevmoo commented Oct 22, 2015

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

@davenotik
Copy link
Author

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}');
    });

@davenotik
Copy link
Author

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants