select raw zlib compression
authorAndy Green <andy@warmcat.com>
Tue, 22 Mar 2011 09:06:52 +0000 (09:06 +0000)
committerAndy Green <andy@warmcat.com>
Tue, 22 Mar 2011 09:06:52 +0000 (09:06 +0000)
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 <andy@warmcat.com>
lib/extension-deflate-stream.c

index 9b7b192..deb793b 100644 (file)
@@ -4,7 +4,8 @@
 #include <string.h>
 #include <assert.h>
 
-
+#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;