1 Star 1 Fork 0

宇宙蒙面侠X/github.com-olivere-elastic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sign_v4.go 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
Oliver Eilhard 提交于 2018-08-18 21:47 +08:00 . Add tests for sub-packages
// Copyright 2012-present Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package aws
import (
"net/http"
"github.com/smartystreets/go-aws-auth"
)
// NewV4SigningClient returns an *http.Client that will sign all requests with AWS V4 Signing.
func NewV4SigningClient(credentials awsauth.Credentials) *http.Client {
return NewV4SigningClientWithHTTPClient(credentials, http.DefaultClient)
}
// NewV4SigningClientWithHTTPClient returns an *http.Client that will sign all requests with AWS V4 Signing.
func NewV4SigningClientWithHTTPClient(credentials awsauth.Credentials, httpClient *http.Client) *http.Client {
return &http.Client{
Transport: V4Transport{
HTTPClient: httpClient,
Credentials: credentials,
},
}
}
// V4Transport is a RoundTripper that will sign requests with AWS V4 Signing
type V4Transport struct {
HTTPClient *http.Client
Credentials awsauth.Credentials
}
// RoundTrip uses the underlying RoundTripper transport, but signs request first with AWS V4 Signing
func (st V4Transport) RoundTrip(req *http.Request) (*http.Response, error) {
// Instead of directly modifying the request then calling http.DefaultTransport,
// instead restart the request with the HTTPClient.Do function,
// because the HTTPClient includes safeguards around not forwarding the
// signed Authorization header to untrusted domains.
return st.HTTPClient.Do(awsauth.Sign4(req, st.Credentials))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/awol2010ex/github.com-olivere-elastic.git
git@gitee.com:awol2010ex/github.com-olivere-elastic.git
awol2010ex
github.com-olivere-elastic
github.com-olivere-elastic
v6.2.37

搜索帮助