I am trying to compress the responses that are sent by http:
import asynchttpserver, asyncdispatch
import zip/zlib
proc handle(req: Request) {.async.} =
if req.headers.hasKey("Accept-Encoding") and req.headers["Accept-Encoding"] == "gzip":
let headers = newHttpHeaders([("Content-Encoding", "gzip")])
await req.respond(Http200, compress("Yes, it was compressed!"), headers)
else:
await req.respond(Http200, "Compress me please!...")
var server = newAsyncHttpServer()
waitFor server.serve(Port(8080), handle)
But I get the following error message when trying to run this code!
Exception message: zlib version mismatch! Exception type: [ZlibStreamError] Error: execution of an external program failed: '/home/hdias/dev/server '
What's is wrong? and how can I get it to work? (my zlib version: zlib-1:1.2.11-3)
Try miniz instead. https://github.com/treeform/miniz
zip/zlib.nim defines ulong as 32-bit, so it fails with 64-bit zlibs.
This site can’t be reached The webpage at http://127.0.0.1:8080/ might be temporarily down or it may have moved permanently to a new web address. ERR_CONTENT_DECODING_FAILED
I wrapped the minz package. Unfortunately minz is not gzip compatible that is needed by http.
I think but i am not 100%, but you might need to use the gzlipfiles protocol: https://github.com/nim-lang/zip/blob/master/zip/gzipfiles.nim not the zlib "plain" protocol which is what minz has.
Your best solution is to figure out the zlib issue. I would play with 32/64 bit ulong stuff.
I think recent commits to fix it on windows broke it for linux/mac? https://github.com/nim-lang/zip/commits/master
I would also try switching to gzlipfiles as well.
I found a solution (on Linux at least) In the zlib.nim file, where types are defines at the top of the file, change Ulong* = uint32 to Ulong* = uint
Also set the 'level' parameter of the compress proc to 'Z_DEFLATED'.