Documentation ¶
Index ¶
- Variables
- func MustTLSConfig(certPEMBlock, keyPEMBlock, caPEMBlock []byte) *tls.Config
- func ReadAndReplaceRequestBody(req *http.Request) (reqBody []byte, err error)
- func ReadAndReplaceResponseBody(resp *http.Response) (respBody []byte, err error)
- func TLSConfig(certPEMBlock, keyPEMBlock, caPEMBlock []byte) (*tls.Config, error)
- type HTTPClient
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // NonceStr 生成一个长度为 2*n 的随机字符串,可 mock NonceStr = func(n int) string { buf := make([]byte, n) _, err := rand.Read(buf) if err != nil { panic(err) } return hex.EncodeToString(buf) } )
View Source
var ( // Now 返回当前时间,可 mock Now = time.Now )
Functions ¶
func MustTLSConfig ¶
MustTLSConfig 是 must 版 TLSConfig
func ReadAndReplaceRequestBody ¶
ReadAndReplaceRequestBody 读取 Request 全部 body 并将 body 替换成 bytes.Buffer
func ReadAndReplaceResponseBody ¶
ReadAndReplaceResponseBody 读取 Response 全部 body 并将 body 替换成 bytes.Buffer
Types ¶
type HTTPClient ¶
type HTTPClient interface { // Do 发送请求,等待响应或错误;实现的行为应当与 http.Client.Do 一致 Do(req *http.Request) (*http.Response, error) }
HTTPClient 是对 http.Client 的一个泛化; 应用可以对 http.Client 进一步封装,例如添加请求/响应的日志记录等
var ( // DefaultHTTPClient 为 wxdriver 默认 HTTPClient,30 秒超时 DefaultHTTPClient HTTPClient = &http.Client{ Timeout: 30 * time.Second, } )
Click to show internal directories.
Click to hide internal directories.