From 26111bc4c6f9084c3bc8cec70b4434ac10869ef8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 22 Mar 2011 09:06:52 +0000 Subject: [PATCH] select raw zlib compression Patrick McManus from Mozilla pointed out that the spec requires a specific kind of zlib compression, which is raw. You can select that by using a funny api in zlib. Mozilla are correcting their compression to this, pywebsockets already did it right in the first place, libwebsockets should now work OK with those. Signed-off-by: Andy Green --- lib/extension-deflate-stream.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/extension-deflate-stream.c b/lib/extension-deflate-stream.c index 9b7b192..deb793b 100644 --- a/lib/extension-deflate-stream.c +++ b/lib/extension-deflate-stream.c @@ -4,7 +4,8 @@ #include #include - +#define LWS_ZLIB_WINDOW_BITS 8 +#define LWS_ZLIB_MEMLEVEL 8 int lws_extension_callback_deflate_stream( struct libwebsocket_context *context, @@ -29,13 +30,15 @@ int lws_extension_callback_deflate_stream( conn->zs_in.zalloc = conn->zs_out.zalloc = Z_NULL; conn->zs_in.zfree = conn->zs_out.zfree = Z_NULL; conn->zs_in.opaque = conn->zs_out.opaque = Z_NULL; - n = inflateInit(&conn->zs_in); + n = inflateInit2(&conn->zs_in, -LWS_ZLIB_WINDOW_BITS); if (n != Z_OK) { fprintf(stderr, "deflateInit returned %d\n", n); return 1; } - n = deflateInit(&conn->zs_out, - DEFLATE_STREAM_COMPRESSION_LEVEL); + n = deflateInit2(&conn->zs_out, + DEFLATE_STREAM_COMPRESSION_LEVEL, Z_DEFLATED, + -LWS_ZLIB_WINDOW_BITS, LWS_ZLIB_MEMLEVEL, + Z_DEFAULT_STRATEGY); if (n != Z_OK) { fprintf(stderr, "deflateInit returned %d\n", n); return 1; -- 2.7.4