httplib

package
v0.0.0-...-495e01f Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRiskyRedirectURL

func IsRiskyRedirectURL(s string) bool

IsRiskyRedirectURL returns true if the URL is considered risky for redirects

func ServeContentByReadSeeker

func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath string, modTime *time.Time, reader io.ReadSeeker)

func ServeContentByReader

func ServeContentByReader(r *http.Request, w http.ResponseWriter, filePath string, size int64, reader io.Reader)

func ServeSetHeaders

func ServeSetHeaders(w http.ResponseWriter, opts *ServeHeaderOptions)

ServeSetHeaders sets necessary content serve headers

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

Types

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request provides more useful methods for requesting one url than http.Request.

func NewRequest

func NewRequest(url, method string) *Request

NewRequest returns *Request with specific method

func (*Request) Body

func (r *Request) Body(data any) *Request

Body adds request raw body. it supports string and []byte.

func (*Request) GoString

func (r *Request) GoString() string

func (*Request) Header

func (r *Request) Header(key, value string) *Request

Header add header item string in request.

func (*Request) Param

func (r *Request) Param(key, value string) *Request

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) Response

func (r *Request) Response() (*http.Response, error)

Response executes request client gets response manually.

func (*Request) SetContext

func (r *Request) SetContext(ctx context.Context) *Request

SetContext sets the request's Context

func (*Request) SetReadWriteTimeout

func (r *Request) SetReadWriteTimeout(readWriteTimeout time.Duration) *Request

func (*Request) SetTLSClientConfig

func (r *Request) SetTLSClientConfig(config *tls.Config) *Request

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*Request) SetTimeout

func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Request

SetTimeout sets connect time out and read-write time out for BeegoRequest.

func (*Request) SetTransport

func (r *Request) SetTransport(transport http.RoundTripper) *Request

SetTransport sets transport to

type ServeHeaderOptions

type ServeHeaderOptions struct {
	ContentType        string // defaults to "application/octet-stream"
	ContentTypeCharset string
	ContentLength      *int64
	Disposition        string // defaults to "attachment"
	Filename           string
	CacheDuration      time.Duration // defaults to 5 minutes
	LastModified       time.Time
}

type Settings

type Settings struct {
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TLSClientConfig  *tls.Config
	Transport        http.RoundTripper
}

Settings is the default settings for http client

Jump to

Keyboard shortcuts

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