Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip compression with asynchttpserver #9175

Open
mrhdias opened this issue Oct 3, 2018 · 2 comments
Open

gzip compression with asynchttpserver #9175

mrhdias opened this issue Oct 3, 2018 · 2 comments

Comments

@mrhdias
Copy link
Contributor

mrhdias commented Oct 3, 2018

How to enabling gzip compression with asynchttpserver if is possible?

@dom96
Copy link
Contributor

dom96 commented Oct 4, 2018

Not possible at the minute. If you want gzip compression you can use nginx in front of it.

@ringabout
Copy link
Member

ringabout commented Feb 16, 2021

see the example from
https://github.com/guzba/zippy/blob/master/examples/http_server.nim

import asyncdispatch, asynchttpserver, zippy

let server = newAsyncHttpServer()

proc cb(req: Request) {.async.} =
  if req.headers["Accept-Encoding"].contains("gzip"):
    # This client supports gzip, send compressed response
    let headers = newHttpHeaders([("Content-Encoding", "gzip")])
    await req.respond(
      Http200,
      compress("gzip'ed response body", BestSpeed, dfGzip),
      headers
    )
  else:
    await req.respond(Http200, "uncompressed response body")

waitFor server.serve(Port(8080), cb)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants