为Go提供压缩的内容 [英] Serving gzipped content for Go
问题描述
我开始用Go编写服务器端应用程序.我想使用Accept-Encoding
请求标头来确定是否使用GZIP
压缩响应实体.我希望找到一种直接使用http.Serve
或http.ServeFile
方法执行此操作的方法.
I'm starting to write server-side applications in Go. I'd like to use the Accept-Encoding
request header to determine whether to compress the response entity using GZIP
. I had hoped to find a way to do this directly using the http.Serve
or http.ServeFile
methods.
这是一个很普遍的要求;我错过了什么还是我需要推出自己的解决方案?
This is quite a general requirement; did I miss something or do I need to roll my own solution?
推荐答案
gzip压缩的HTTP响应尚无开箱即用"支持.但是添加它是微不足道的.看看
There is no "out of the box" support for gzip-compressed HTTP responses yet. But adding it is pretty trivial. Have a look at
https://gist.github.com/the42/1956518
也
https://groups.google.com/forum/?fromgroups =#!topic/golang-nuts/cgUp8_ATNtc
这篇关于为Go提供压缩的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!