Snappy压缩是否适合Mochiweb,HTTP压缩?

时间:2012-08-27 12:00:56

标签: erlang mochiweb

我使用Snappy(https://github.com/fdmanana/snappy-erlang-nif)作为Mochiweb应用程序上HTTP压缩的zlib替代品。

虽然Snappy一般对我有效,并且zlib在发送之前压缩响应工作正常,但使用Snappy作为zlib替换会导致客户端浏览器混淆响应。

  1. Snappy是否编码为utf-8字符集?
  2. 客户端浏览器一般都知道如何解压缩Snappy压缩文档吗?
  3. 我做了什么明显的事情吗?
  4. 这有效:

    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.
    

    这不是

    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.
    

1 个答案:

答案 0 :(得分:0)

没有一个浏览器支持snappy压缩;)你不能选择任何你喜欢的压缩算法,你必须选择浏览器支持的算法。大多数浏览器只支持deflate和gzip。