1
我正在使用Snappy(https://github.com/fdmanana/snappy-erlang-nif)作爲Mochiweb應用程序上的HTTP壓縮的zlib替代品。快速壓縮適合Mochiweb,HTTP壓縮嗎?
雖然斯納皮做工一般對我來說,和zlib工作正常發送出來,使用斯納皮作爲客戶端的瀏覽器錯亂的響應zlib的置換結果之前壓縮響應。
- Snappy會編碼爲utf-8字符集嗎?
- 一般來說,客戶端瀏覽器是否知道如何解壓縮Snappy壓縮文檔?
- 我做的事情顯然很少?
這工作:
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.
這就是爲什麼我們有內容協商。您應該實際檢查請求標頭以查看您可以應用的壓縮類型,即「Accept」標頭。 –