简体   繁体   中英

How to gzip the output in Rikulo Stream?

I'd like to compress the HTTP response in Rikulo Stream . Do I have to invoke GZIP explicitly? Or, there is an option to enable?

You can configure it at startup as follows:

new StreamServer().start()
.then((HttpChannel channel) {
  channel.httpServer.autoCompress = true;
});

I haven't tried it and I didn't use Rikulo Stream myself yet but according to server example code I found in the Github Repo it should be possible to set it like

GZIP compression was the default for Dart HTTP server until recently but was changed and needs to be activated explicitely.

void serverInfo(HttpConnect connect) {
  final info = {"name": "Rikulo Stream", "version": connect.server.version};
  server.
      ..autoCompress = true;
      ..defaultResponseHeaders.chunkedTransferEncoding = true;

  connect.response
    ..headers.contentType = getContentType("json")
    ..write(JSON.encode(info));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM