为Go提供压缩的内容 [英] Serving gzipped content for Go

查看:88
本文介绍了为Go提供压缩的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始用Go编写服务器端应用程序.我想使用Accept-Encoding请求标头来确定是否使用GZIP压缩响应实体.我希望找到一种直接使用http.Servehttp.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆