http

package
v0.0.0-...-fa4cddc Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_REDIRECT_TIMES = 10

Variables

View Source
var (
	ErrRetryNeeded      = errors.New("req need retry")
	ErrAbnormalRespCode = errors.New("abnormal resp code")
)
View Source
var (
	ErrIllegalParam = errors.New("param is illegal")
)

result must be an address

View Source
var ShouldRetry = func(code int, err error) bool {
	urlErr, ok := err.(*url.Error)
	if ok && urlErr.Timeout() {
		return true
	}

	if err == nil {
		return false
	}

	if strings.Contains(err.Error(), "use of closed network connection") {
		return true
	}

	if strings.Contains(err.Error(), "connection reset by peer") {
		return true
	}

	return false
}

retry on timeout only

Functions

This section is empty.

Types

type HttpClient

type HttpClient struct {
	*conf.HttpCfg

	ClientId string
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(cfg *conf.HttpCfg, user *conf.UserInfo, clientID string,
	log *util.ClientLogger, cfaCfg *conf.Config) *HttpClient

func (*HttpClient) Close

func (h *HttpClient) Close()

func (*HttpClient) DoPostWithJson

func (p *HttpClient) DoPostWithJson(api_uri string, params interface{}, result interface{}, log *util.ClientLogger) (err error)

func (*HttpClient) UpdateHosts

func (h *HttpClient) UpdateHosts(Hosts string)

type HttpRequest

type HttpRequest struct {
	*http.Request
	Body io.ReaderAt
}

type HttpRequest

type RetryReader

type RetryReader struct {
	Reader io.ReaderAt
	Offset int64
}

prevents problems when the same host tries

func (*RetryReader) Close

func (p *RetryReader) Close() error

func (*RetryReader) Read

func (p *RetryReader) Read(val []byte) (n int, err error)

type Transport

type Transport struct {
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

Jump to

Keyboard shortcuts

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