Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

识别response中的content-encoding #343

Closed
Sora233 opened this issue Sep 21, 2022 · 3 comments
Closed

识别response中的content-encoding #343

Sora233 opened this issue Sep 21, 2022 · 3 comments

Comments

@Sora233
Copy link
Contributor

Sora233 commented Sep 21, 2022

content-encoding会指定response body的压缩方法,希望可以支持自动识别常用的压缩,gzip, deflate, br等,相信这是一个比较common的部分

@guonaihong
Copy link
Owner

guonaihong commented Sep 21, 2022

可以实现下。
我找了一些资料,应该和你描述的需求接近。https://developer.mozilla.org/zh-CN/docs/web/http/headers/content-encoding

如果是透明转发的场景,自动解码不一样是最优的方式,目前比较倾向来个开关控制下,伪代码如下。

.AutoDecodeBody() //加这样的接口
s := ""
gout.GET(url).AutoDecodeBody().BindBody(&s).Do()
// 这样如果可以要解压之后的内容就调用下AutoDecodeBody,如果要原始的压缩内容就不调用这个接口

@guonaihong
Copy link
Owner

备忘:这个issue完成了。在测试的时候发现,net/http里面已经做了gzip自动解码的动作,源代码位于 /~https://github.com/golang/go/blob/master/src/net/http/transport.go#L2211
位置http包-->transport.go -->readLoop函数内部。
AutoDecodeBody开关会实现deflate, br两种格式的解码。

@guonaihong guonaihong mentioned this issue Dec 10, 2022
@guonaihong
Copy link
Owner

有机会玩下v0.3.2版本,这个issue暂时关闭了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants