httputil

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 21 Imported by: 58

README

httputil

The package contains various helpers related to http protocol

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// reasonably high default allowed allocs
	DefaultBytesBufferAlloc = int64(10000)
)
View Source
var (
	MaxBodyRead, _ = units.FromHumanSize("4mb")
)

Functions

func AllHTTPMethods

func AllHTTPMethods() []string

AllHTTPMethods contains all available HTTP methods

func ChangePoolSize added in v0.0.84

func ChangePoolSize(x int64) error

func DrainResponseBody

func DrainResponseBody(resp *http.Response)

DrainResponseBody drains the response body and closes it.

func DumpRequest

func DumpRequest(req *http.Request) (string, error)

DumpRequest to string

func DumpResponseHeadersAndRaw

func DumpResponseHeadersAndRaw(resp *http.Response) (headers, fullresp []byte, err error)

DumpResponseHeadersAndRaw returns http headers and response as strings

func DumpResponseIntoBuffer added in v0.0.80

func DumpResponseIntoBuffer(resp *http.Response, body bool, buff *bytes.Buffer) (err error)

DumpResponseIntoBuffer dumps a http response without allocating a new buffer for the response body.

func GetPoolSize added in v0.0.84

func GetPoolSize() int64

Types

type ChainItem

type ChainItem struct {
	Request    []byte
	Response   []byte
	StatusCode int
	Location   string
	RequestURL string
}

ChainItem request=>response Deprecated: use ResponseChain instead which is more efficient and lazy

func GetChain

func GetChain(r *http.Response) (chain []ChainItem, err error)

GetChain if redirects Deprecated: use ResponseChain instead which is more efficient and lazy

type CookieJar added in v0.6.0

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

CookieJar is a thread-safe wrapper around http.CookieJar

func NewCookieJar added in v0.6.0

func NewCookieJar(opts ...Option) (*CookieJar, error)

New creates a new thread-safe cookie jar with the given options If no jar is provided, creates a simple in-memory cookie jar

func (*CookieJar) Cookies added in v0.6.0

func (cj *CookieJar) Cookies(u *url.URL) []*http.Cookie

Cookies implements http.CookieJar.Cookies

func (*CookieJar) SetCookies added in v0.6.0

func (cj *CookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements http.CookieJar.SetCookies

type Option added in v0.6.0

type Option func(*CookieJar)

Option represents a configuration option for the cookie jar

func WithCookieJar added in v0.6.0

func WithCookieJar(jar http.CookieJar) Option

WithCookieJar sets an existing cookie jar to wrap

type ResponseChain added in v0.0.80

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

ResponseChain is a response chain for a http request on every call to previous it returns the previous response if it was redirected.

func NewResponseChain added in v0.0.80

func NewResponseChain(resp *http.Response, maxBody int64) *ResponseChain

NewResponseChain creates a new response chain for a http request with a maximum body size. (if -1 stick to default 4MB)

func (*ResponseChain) Body added in v0.0.80

func (r *ResponseChain) Body() *bytes.Buffer

Body returns the current response body in the chain

func (*ResponseChain) Close added in v0.0.80

func (r *ResponseChain) Close()

Close the response chain and releases the buffers.

func (*ResponseChain) Fill added in v0.0.80

func (r *ResponseChain) Fill() error

Fill buffers

func (*ResponseChain) FullResponse added in v0.0.80

func (r *ResponseChain) FullResponse() *bytes.Buffer

FullResponse returns the current response in the chain

func (*ResponseChain) Has added in v0.0.80

func (r *ResponseChain) Has() bool

Has returns true if the response chain has a response

func (*ResponseChain) Headers added in v0.0.80

func (r *ResponseChain) Headers() *bytes.Buffer

Response returns the current response in the chain

func (*ResponseChain) Previous added in v0.0.80

func (r *ResponseChain) Previous() bool

previous updates response pointer to previous response if it was redirected and returns true else false

func (*ResponseChain) Request added in v0.0.80

func (r *ResponseChain) Request() *http.Request

Request is request of current response

func (*ResponseChain) Response added in v0.0.80

func (r *ResponseChain) Response() *http.Response

Response is response of current response

Jump to

Keyboard shortcuts

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