gpt4 book ai didi

戈朗 : Can I remove response headers coming from ReverseProxy?

转载 作者:IT王子 更新时间:2023-10-29 01:02:08 27 4
gpt4 key购买 nike

我正在使用 httputil.ReverseProxy 将 Amazon s3 文件代理给我的客户。我想隐藏所有来自 Amazon 的 header - 是否可以在无需重新实现反向代理的情况下实现?

proxy := httputil.ReverseProxy{Director: func(r *http.Request) {
r.Header = http.Header{} // Don't send client's request headers to Amazon.
r.URL = proxyURL
r.Host = proxyURL.Host
}}
proxy.ServeHTTP(w, r) // How do I remove w.Headers ?

最佳答案

您可以实现 ReverseProxy.Transport

type MyTransport struct{
header http.Header
}
func (t MyTransport) RoundTrip(r *Request) (*Response, error){
resp, err := http.DefaultTransport.RoundTrip(r)
resp.Header = t.header
return resp, err
}
mytransport := MyTransport{
//construct Header
}
proxy := httputil.ReverseProxy{Director: func(r *http.Request) {
r.Header = http.Header{} // Don't send client's request headers to Amazon.
r.URL = proxyURL
r.Host = proxyURL.Host
},
Transport: mytransport,
}

关于戈朗 : Can I remove response headers coming from ReverseProxy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013682/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com