httputils

package module
v0.0.0-...-6d8be5c Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = fasthttp.Client{
	MaxConnsPerHost:     50000,
	MaxIdleConnDuration: time.Second * 15,
	MaxConnDuration:     time.Second * 10,
	ReadTimeout:         time.Second * 90,
	MaxConnWaitTimeout:  time.Second * 5,
}

DefaultClient is a default client

Functions

This section is empty.

Types

type ContentType

type ContentType string
const (
	TextHTML          ContentType = "text/html"
	TextPlain         ContentType = "text/plain"
	AppOctetStream    ContentType = "application/octet-stream"
	AppJSON           ContentType = "application/json"
	AppFormUrlencoded ContentType = "application/x-www-form-urlencoded"
	AppXML            ContentType = "application/xml"
	MultiFormData     ContentType = "multipart/form-data"
)

func NewContentType

func NewContentType(contentType string) ContentType

func (ContentType) SetBoundary

func (c ContentType) SetBoundary(boundary string) ContentType

func (ContentType) SetCharset

func (c ContentType) SetCharset(charset string) ContentType

type Encoder

type Encoder interface {
	Encode(v any) error
}

type FormDataEncoder

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

func (FormDataEncoder) Encode

func (f FormDataEncoder) Encode(_ any) error

type GetEncoder

type GetEncoder func(buf io.Writer) Encoder

func FormData

func FormData(fn func(*multipart.Writer) error) GetEncoder

func JSON

func JSON() GetEncoder

type HTTP

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

func Connect

func Connect(uri ...string) *HTTP

func Delete

func Delete(uri ...string) *HTTP

func Get

func Get(uri ...string) *HTTP
func Head(uri ...string) *HTTP

func Options

func Options(uri ...string) *HTTP

func Patch

func Patch(uri ...string) *HTTP

func Post

func Post(uri ...string) *HTTP

func Put

func Put(uri ...string) *HTTP

func Trace

func Trace(uri ...string) *HTTP

func (*HTTP) Add

func (h *HTTP) Add(fn ...Handler) *HTTP

func (*HTTP) AddHeader

func (h *HTTP) AddHeader(k, v string) *HTTP

func (*HTTP) AppendBody

func (h *HTTP) AppendBody(p []byte) *HTTP

func (*HTTP) AppendBodyString

func (h *HTTP) AppendBodyString(s string) *HTTP

func (*HTTP) DelAllCookies

func (h *HTTP) DelAllCookies() *HTTP

func (*HTTP) DelCookie

func (h *HTTP) DelCookie(k string) *HTTP

func (*HTTP) DelHeader

func (h *HTTP) DelHeader(k string) *HTTP

func (*HTTP) DoRelease

func (h *HTTP) DoRelease() error

func (*HTTP) ParserData

func (h *HTTP) ParserData(arr ...Parser) *HTTP

func (*HTTP) Put

func (h *HTTP) Put()

func (*HTTP) ReadBody

func (h *HTTP) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int) *HTTP

func (*HTTP) Request

func (h *HTTP) Request(retry int, isFail func(error, *fasthttp.Response) bool, timeout time.Duration) *HTTP

func (*HTTP) SetBody

func (h *HTTP) SetBody(body []byte) *HTTP

func (*HTTP) SetBodyStream

func (h *HTTP) SetBodyStream(bodyStream io.Reader, bodySize int) *HTTP

func (*HTTP) SetBodyString

func (h *HTTP) SetBodyString(body string) *HTTP

func (*HTTP) SetBodyWithEncoder

func (h *HTTP) SetBodyWithEncoder(ge GetEncoder, body any) *HTTP

func (*HTTP) SetByteRange

func (h *HTTP) SetByteRange(startPos, endPos int) *HTTP

func (*HTTP) SetClient

func (h *HTTP) SetClient(client *fasthttp.Client) *HTTP

func (*HTTP) SetConnectionClose

func (h *HTTP) SetConnectionClose() *HTTP

func (*HTTP) SetContentEncoding

func (h *HTTP) SetContentEncoding(contentEncoding string) *HTTP

func (*HTTP) SetContentLength

func (h *HTTP) SetContentLength(contentLength int) *HTTP

func (*HTTP) SetContentType

func (h *HTTP) SetContentType(contentType ContentType) *HTTP

func (*HTTP) SetCookie

func (h *HTTP) SetCookie(k, v string) *HTTP

func (*HTTP) SetHeader

func (h *HTTP) SetHeader(k, v string) *HTTP

func (*HTTP) SetHost

func (h *HTTP) SetHost(host string) *HTTP

func (*HTTP) SetMethod

func (h *HTTP) SetMethod(method Method) *HTTP

func (*HTTP) SetMultipartFormBoundary

func (h *HTTP) SetMultipartFormBoundary(boundary string) *HTTP

func (*HTTP) SetProtocol

func (h *HTTP) SetProtocol(p string) *HTTP

func (*HTTP) SetProxy

func (h *HTTP) SetProxy(addr string) *HTTP

func (*HTTP) SetReferer

func (h *HTTP) SetReferer(referer string) *HTTP

func (*HTTP) SetRequestURI

func (h *HTTP) SetRequestURI(requestURI string) *HTTP

func (*HTTP) SetUserAgent

func (h *HTTP) SetUserAgent(userAgent string) *HTTP

type Handler

type Handler func(
	client *fasthttp.Client,
	req *fasthttp.Request,
	resp *fasthttp.Response,
) error

type Method

type Method string

Method https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

const (
	MethodGet     Method = "GET"     // RFC 7231, 4.3.1
	MethodHead    Method = "HEAD"    // RFC 7231, 4.3.2
	MethodPost    Method = "POST"    // RFC 7231, 4.3.3
	MethodPut     Method = "PUT"     // RFC 7231, 4.3.4
	MethodPatch   Method = "PATCH"   // RFC 5789
	MethodDelete  Method = "DELETE"  // RFC 7231, 4.3.5
	MethodConnect Method = "CONNECT" // RFC 7231, 4.3.6
	MethodOptions Method = "OPTIONS" // RFC 7231, 4.3.7
	MethodTrace   Method = "TRACE"   // RFC 7231, 4.3.8
)

func NewMethod

func NewMethod(method string) Method

type Parser

type Parser func(resp *fasthttp.Response) error

func HeaderParser

func HeaderParser(m map[string]string) Parser

func JSONParser

func JSONParser(v any) Parser

Jump to

Keyboard shortcuts

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