I am using Snappy (https://github.com/fdmanana/snappy-erlang-nif) as a zlib replacement for HTTP compression on a Mochiweb application.
While Snappy works in general for me, and zlib works fine for compressing responses before sending them out, using Snappy as a zlib replacement results in client-browsers garbling the response.
This works:
success(Req, Code, Body) ->
case iolist_size(Body) of
N when N > 1024000 ->
Data = zlib:gzip(Body),
Req:respond({Code, [{"Vary","Accept-Encoding"},
{"Content-Encoding","gzip"},
{"Content-Type", "application/json"}],
Data});
_ ->
Req:respond({Code, [{"Content-Type", "application/json"}], Body})
end.
This doesn't
success(Req, Code, Body) ->
case iolist_size(Body) of
N when N > 1024000 ->
{ok, Data} = snappy:compress(Body),
Req:respond({Code, [{"Vary","Accept-Encoding"},
{"Content-Encoding","snappy"},
{"Content-Type", "application/json"}],
Data});
_ ->
Req:respond({Code, [{"Content-Type", "application/json"}], Body})
end.
There's not one browser which does support snappy compression ;) You can't choose any compression algorithm you like, you have to choose the algorithms browsers support. And most browsers only support deflate and gzip.