httpclient

package
v0.0.0-...-83feed8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 9 Imported by: 0

README

支持http http2 ssl认证 ssl双向认证 Cookies的HttpClient封装

NewHttpClient(option Options) (*http.Client, error) 
type Options struct {
    JarEnabled           bool              // 是否启用 cookies
    Timeout              time.Duration     // 默认10秒
    DialTimeout          time.Duration     //连接超时时间 默认3秒
    TLSHandshakeTimeout  time.Duration     // 默认3秒
    IdleConnTimeout      time.Duration     // 默认50秒
    MaxConnsPerHost      int               // 每个域名最多连接数量
    MaxIdleConns         int               // 最多允许的空闲连接数量
    MaxIdleConnsPerHost  int               // 每个域名最多允许的空闲连接数量
    WriteBufferSize      int               // 读写缓冲区 根据业务调整合适 如果都是小报文响应 适当调小
    ReadBufferSize       int               // 读写缓冲区 根据业务调整合适 如果都是小报文请求 适当调小
    InsecureSkipVerify   bool              // 默认false
    CertFilePath         string            // 从文件中加载证书 跟Certificates合并
    KeyFilePath          string            // 从文件中加载证书 跟Certificates合并
    Certificates         []tls.Certificate // 双向认证时使用
    ProxyFromEnvironment bool              // 是否用环境代理 默认不用代理
    // NextProtos           []string          // 协商使用的协议 由http和http2包内不自动设置 ProtoH1  ProtoH2
}

Documentation

Overview

支持http http2 ssl认证 ssl双向认证 Cookies的HttpClient封装

Index

Constants

View Source
const (
	DefaultDialTimeout         = 3 * time.Second
	DefaultTimeout             = 10 * time.Second
	DefaultTLSHandshakeTimeout = 3 * time.Second
	DefaultIdleConnTimeout     = 50 * time.Second
	DefaultMaxConnsPerHost     = 30
	DefaultMaxIdleConns        = 1000
	DefaultMaxIdleConnsPerHost = 1

	ProtoH1 = "http/1.1"
	ProtoH2 = "h2"
)

Variables

This section is empty.

Functions

func ErrorCanRetry

func ErrorCanRetry(err error) bool

哪些error可以确定服务端一定没有收到可以重新发起请求

func NewHttpClient

func NewHttpClient(option Options) (*http.Client, error)

Types

type Options

type Options struct {
	JarEnabled           bool              // 是否启用 cookies
	Timeout              time.Duration     // 默认10秒
	DialTimeout          time.Duration     //连接超时时间 默认3秒
	TLSHandshakeTimeout  time.Duration     // 默认3秒
	IdleConnTimeout      time.Duration     // 默认50秒
	MaxConnsPerHost      int               // 每个域名最多连接数量
	MaxIdleConns         int               // 最多允许的空闲连接数量
	MaxIdleConnsPerHost  int               // 每个域名最多允许的空闲连接数量
	WriteBufferSize      int               // 读写缓冲区 根据业务调整合适 如果都是小报文响应 适当调小
	ReadBufferSize       int               // 读写缓冲区 根据业务调整合适 如果都是小报文请求 适当调小
	InsecureSkipVerify   bool              // 默认false
	CertFilePath         string            // 从文件中加载证书 跟Certificates合并
	KeyFilePath          string            // 从文件中加载证书 跟Certificates合并
	Certificates         []tls.Certificate // 双向认证时使用
	ProxyFromEnvironment bool              // 是否用环境代理 默认不用代理

}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL