requests

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDefaultMiddleware = errors.New("middleware stop")

ErrDefaultMiddleware The middleware stops and the request returns the default error.

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

Marshal Serialization, the default official JSON processor.

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

Unmarshal Deserialization, default to the official JSON processor.

Functions

func InitH2CClient added in v1.8.8

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

InitH2CClient Initialize H2C client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.

func InitHTTPClient added in v1.8.0

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

InitHTTPClient Initialize HTTP client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.

func InstallMiddleware added in v1.8.4

func InstallMiddleware(handle ...Handler)

InstallMiddleware Install the middleware processor.

func SetH2CClient added in v1.8.8

func SetH2CClient(client Client)

SetH2CClient Set up H2C client.

func SetHTTPClient added in v1.8.8

func SetHTTPClient(client Client)

SetHTTPClient Set up client.

Types

type Client added in v1.8.8

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client The client interface is defined.

type ClientImpl added in v1.8.8

type ClientImpl struct {
	*http.Client
}

ClientImpl The implementation of the client interface.

func NewH2CClient added in v1.8.8

func NewH2CClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl

NewH2CClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.

func NewHTTPClient added in v1.8.8

func NewHTTPClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl

NewHTTPClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.

func (*ClientImpl) Do added in v1.8.8

func (client *ClientImpl) Do(req *http.Request) (*http.Response, error)

Do Launch an http request.

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 Link information for the connection.

type Handler

type Handler func(Middleware)

Handler The definition of the middleware processor.

type Middleware

type Middleware interface {
	//Go on.
	Next()
	Stop(...error)
	// Returns the standard request object.
	GetRequest() *http.Request
	// Returns carry information for HTTP requests.
	GetRespone() *Response
	// Returns http package data.
	GetResponeBody() []byte
	IsStopped() bool
	// Is HTTP/2 Cleartext Request.
	IsH2C() bool
	Context() context.Context
	WithContextFromMiddleware(context.Context)
	// Turn on link tracking for HTTP connections.
	EnableTraceFromMiddleware()
	// Set up client.
	SetClientFromMiddleware(Client)
}

Middleware The interface definition of the middleware.

type Request

type Request interface {
	// HTTP POST method.
	Post() Request
	// HTTP PUT method.
	Put() Request
	// HTTP GET method.
	Get() Request
	// HTTP DELETE method.
	Delete() Request
	// HTTP HEAD method.
	Head() Request
	// HTTP OPTIONS method.
	Options() Request
	// Set up JSON data.
	SetJSONBody(obj interface{}) Request
	// Set the original data.
	SetBody(byts []byte) Request
	// Set up Form data.
	SetFormBody(url.Values) Request
	// Set up File data.
	SetFile(field, file string) Request
	// The data is returned after the request and converted to JSON data.
	ToJSON(obj interface{}) *Response
	// The data is returned after the request and converted into a string.
	ToString() (string, *Response)
	// The data is returned after the request and converted into a []byte.
	ToBytes() ([]byte, *Response)
	// The data is returned after the request and converted to XML data.
	ToXML(v interface{}) *Response
	// Set the request parameters.
	SetQueryParam(key string, value interface{}) Request
	// Set the request parameters.
	SetQueryParams(map[string]interface{}) Request
	URL() string
	Context() context.Context
	WithContext(context.Context) Request
	// idempotent request processing, need to fill in KEY.
	Singleflight(key ...interface{}) Request
	// Set up HTTP Header information.
	SetHeader(header http.Header) Request
	// Add HTTP Header information.
	AddHeader(key, value string) Request
	// Returns the header of the current request.
	Header() http.Header
	// Returns the Request of the standard library.
	GetStdRequest() *http.Request
	// Add cookie information.
	AddCookie(*http.Cookie) Request
	// Turn on link tracking.
	EnableTrace() Request
	// Set up client.
	SetClient(client Client) Request
}

Request The interface definition of the HTTP request package.

func NewH2CRequest

func NewH2CRequest(rawurl string) Request

NewH2CRequest Create an HTTP H2C request object. The URL of the incoming HTTP.

func NewHTTPRequest added in v1.8.0

func NewHTTPRequest(rawurl string) Request

NewHTTPRequest Create an HTTP request object. The URL of the incoming HTTP.

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 is a return carry information for HTTP requests.

func (*Response) Clone added in v1.8.1

func (res *Response) Clone() *Response

Clone Copy a new one.

func (*Response) Cookie added in v1.8.9

func (res *Response) Cookie(name string) *http.Cookie

Cookie returns cookie's value by its name returns empty string if nothing was found.

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 Link information for the connection.

Jump to

Keyboard shortcuts

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