requests

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: Apache-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultH2CClient .
	DefaultH2CClient *http.Client

	// DefaultHTTPClient .
	DefaultHTTPClient *http.Client
)
View Source
var Marshal func(v interface{}) ([]byte, error)

Marshal .

View Source
var Unmarshal func(data []byte, v interface{}) error

Unmarshal .

Functions

func InitH2cClient added in v1.8.0

func InitH2cClient(rwTimeout time.Duration, connectTimeout ...time.Duration)

InitH2cClient .

func InitHTTPClient added in v1.8.0

func InitHTTPClient(rwTimeout time.Duration, connectTimeout ...time.Duration)

InitHTTPClient .

func InstallH2CClient added in v1.8.2

func InstallH2CClient(client *http.Client)

InstallH2CClient .

func InstallHTTPClient added in v1.8.2

func InstallHTTPClient(client *http.Client)

InstallHTTPClient .

func InstallMiddleware added in v1.8.4

func InstallMiddleware(handle ...Handler)

InstallMiddleware .

Types

type HTTPRequest added in v1.8.0

type HTTPRequest struct {
	StdRequest      *http.Request
	Response        Response
	Params          url.Values
	RawURL          string
	SingleflightKey string

	Client *http.Client
	// contains filtered or unexported fields
}

HTTPRequest .

func (*HTTPRequest) AddCookie added in v1.8.1

func (req *HTTPRequest) AddCookie(c *http.Cookie) Request

AddCookie .

func (*HTTPRequest) AddHeader added in v1.8.0

func (req *HTTPRequest) AddHeader(key, value string) Request

AddHeader .

func (*HTTPRequest) Context added in v1.8.1

func (req *HTTPRequest) Context() context.Context

Context .

func (*HTTPRequest) Delete added in v1.8.0

func (req *HTTPRequest) Delete() Request

Delete .

func (*HTTPRequest) EnableTrace added in v1.8.1

func (req *HTTPRequest) EnableTrace() Request

EnableTrace .

func (*HTTPRequest) EnableTraceFromMiddleware added in v1.8.1

func (req *HTTPRequest) EnableTraceFromMiddleware()

EnableTraceFromMiddleware .

func (*HTTPRequest) Get added in v1.8.0

func (req *HTTPRequest) Get() Request

Get .

func (*HTTPRequest) GetRequest added in v1.8.0

func (req *HTTPRequest) GetRequest() *http.Request

GetRequest .

func (*HTTPRequest) GetRespone added in v1.8.0

func (req *HTTPRequest) GetRespone() *Response

GetRespone .

func (*HTTPRequest) GetResponeBody added in v1.8.1

func (req *HTTPRequest) GetResponeBody() []byte

GetResponeBody .

func (*HTTPRequest) GetStdRequest added in v1.8.0

func (req *HTTPRequest) GetStdRequest() *http.Request

GetStdRequest .

func (*HTTPRequest) Head added in v1.8.0

func (req *HTTPRequest) Head() Request

Head .

func (*HTTPRequest) Header added in v1.8.0

func (req *HTTPRequest) Header() http.Header

Header .

func (*HTTPRequest) IsStopped added in v1.8.0

func (req *HTTPRequest) IsStopped() bool

IsStopped .

func (*HTTPRequest) Next added in v1.8.0

func (req *HTTPRequest) Next()

Next .

func (*HTTPRequest) Options added in v1.8.1

func (req *HTTPRequest) Options() Request

Options .

func (*HTTPRequest) Post added in v1.8.0

func (req *HTTPRequest) Post() Request

Post .

func (*HTTPRequest) Put added in v1.8.0

func (req *HTTPRequest) Put() Request

Put .

func (*HTTPRequest) SetBody added in v1.8.0

func (req *HTTPRequest) SetBody(byts []byte) Request

SetBody .

func (*HTTPRequest) SetClient added in v1.8.5

func (req *HTTPRequest) SetClient(client *http.Client) Request

SetClient .

func (*HTTPRequest) SetHeader added in v1.8.0

func (req *HTTPRequest) SetHeader(header http.Header) Request

SetHeader .

func (*HTTPRequest) SetJSONBody added in v1.8.0

func (req *HTTPRequest) SetJSONBody(obj interface{}) Request

SetJSONBody .

func (*HTTPRequest) SetQueryParam added in v1.8.1

func (req *HTTPRequest) SetQueryParam(key string, value interface{}) Request

SetQueryParam .

func (*HTTPRequest) SetQueryParams added in v1.8.1

func (req *HTTPRequest) SetQueryParams(m map[string]interface{}) Request

SetQueryParams .

func (*HTTPRequest) Singleflight added in v1.8.0

func (req *HTTPRequest) Singleflight(key ...interface{}) Request

Singleflight .

func (*HTTPRequest) Stop added in v1.8.0

func (req *HTTPRequest) Stop(e ...error)

Stop .

func (*HTTPRequest) ToBytes added in v1.8.0

func (req *HTTPRequest) ToBytes() ([]byte, *Response)

ToBytes .

func (*HTTPRequest) ToJSON added in v1.8.0

func (req *HTTPRequest) ToJSON(obj interface{}) *Response

ToJSON .

func (*HTTPRequest) ToString added in v1.8.0

func (req *HTTPRequest) ToString() (string, *Response)

ToString .

func (*HTTPRequest) ToXML added in v1.8.0

func (req *HTTPRequest) ToXML(v interface{}) *Response

ToXML .

func (*HTTPRequest) URL added in v1.8.0

func (req *HTTPRequest) URL() string

URL .

func (*HTTPRequest) WithContext added in v1.8.0

func (req *HTTPRequest) WithContext(ctx context.Context) Request

WithContext .

func (*HTTPRequest) WithContextFromMiddleware added in v1.8.1

func (req *HTTPRequest) WithContextFromMiddleware(ctx context.Context)

WithContextFromMiddleware .

type HTTPTraceInfo added in v1.8.1

type HTTPTraceInfo struct {
	DNSLookup    time.Duration
	ConnTime     time.Duration
	TCPConnTime  time.Duration
	TLSHandshake time.Duration

	ServerTime   time.Duration
	ResponseTime time.Duration
	TotalTime    time.Duration

	IsConnReused bool

	IsConnWasIdle bool
	ConnIdleTime  time.Duration
}

HTTPTraceInfo .

type Handler

type Handler func(Middleware)

Handler .

type Middleware

type Middleware interface {
	Next()
	Stop(...error)
	GetRequest() *http.Request
	GetRespone() *Response
	GetResponeBody() []byte
	IsStopped() bool
	Context() context.Context
	WithContextFromMiddleware(context.Context)
	EnableTraceFromMiddleware()
}

Middleware .

type Request

type Request interface {
	Post() Request
	Put() Request
	Get() Request
	Delete() Request
	Head() Request
	Options() Request
	SetJSONBody(obj interface{}) Request
	SetBody(byts []byte) Request
	ToJSON(obj interface{}) *Response
	ToString() (string, *Response)
	ToBytes() ([]byte, *Response)
	ToXML(v interface{}) *Response
	SetQueryParam(key string, value interface{}) Request
	SetQueryParams(map[string]interface{}) Request
	URL() string
	Context() context.Context
	WithContext(context.Context) Request
	Singleflight(key ...interface{}) Request
	SetHeader(header http.Header) Request
	AddHeader(key, value string) Request
	Header() http.Header
	GetStdRequest() *http.Request
	AddCookie(*http.Cookie) Request
	EnableTrace() Request
	SetClient(client *http.Client) Request
}

Request .

func NewH2CRequest

func NewH2CRequest(rawurl string) Request

NewH2CRequest .

func NewHTTPRequest added in v1.8.0

func NewHTTPRequest(rawurl string) Request

NewHTTPRequest .

type Response

type Response struct {
	Error         error
	HTTP11        bool
	ContentType   string
	Status        string // e.g. "200 OK"
	StatusCode    int    // e.g. 200
	Proto         string // e.g. "HTTP/1.0"
	ProtoMajor    int    // e.g. 1
	ProtoMinor    int    // e.g. 0
	Header        http.Header
	ContentLength int64
	Uncompressed  bool
	// contains filtered or unexported fields
}

Response .

func (*Response) Clone added in v1.8.1

func (res *Response) Clone() *Response

Clone .

func (*Response) Cookies added in v1.8.1

func (res *Response) Cookies() []*http.Cookie

Cookies parses and returns the cookies set in the Set-Cookie headers.

func (*Response) ProtoAtLeast added in v1.8.1

func (res *Response) ProtoAtLeast(major, minor int) bool

ProtoAtLeast reports whether the HTTP protocol used in the response is at least major.minor.

func (*Response) TraceInfo added in v1.8.1

func (res *Response) TraceInfo() HTTPTraceInfo

TraceInfo .

Jump to

Keyboard shortcuts

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