request

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomString

func RandomString() string

func SanitizeCookieName

func SanitizeCookieName(n string) string

func SanitizeCookieValue

func SanitizeCookieValue(v string, quoted bool) string

sanitizeCookieValue produces a suitable cookie-value from v. It receives a quoted bool indicating whether the value was originally quoted. https://tools.ietf.org/html/rfc6265#section-4.1.1

cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
          ; US-ASCII characters excluding CTLs,
          ; whitespace DQUOTE, comma, semicolon,
          ; and backslash

We loosen this as spaces and commas are common in cookie values thus we produce a quoted cookie-value if v contains commas or spaces. See https://golang.org/issue/7243 for the discussion.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type ClientOption

type ClientOption func(*clientOptions)

Option defines the configuration function type for request options

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

func WithCookieJar

func WithCookieJar(jar http.CookieJar) ClientOption

WithCookieJar sets cookies

func WithFollowRedirects

func WithFollowRedirects(followRedirects bool, maxRedirects int) ClientOption

func WithLogger

func WithLogger(logger resty.Logger) ClientOption

func WithProxy

func WithProxy(proxy string) ClientOption

WithProxy sets proxy

func WithTLSClientConfig

func WithTLSClientConfig(config *tls.Config) ClientOption

WithTLSClientConfig sets SSL/TLS options

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout duration

func WithTransport

func WithTransport(transport http.RoundTripper) ClientOption

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(options ...ClientOption) *HTTPClient

func (*HTTPClient) Close

func (c *HTTPClient) Close() error

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(url string, options *Options) (*Response, error)

Delete sends a DELETE request

func (*HTTPClient) Get

func (c *HTTPClient) Get(url string, options *Options) (*Response, error)

Get sends a GET request

func (*HTTPClient) Head

func (c *HTTPClient) Head(url string, options *Options) (*Response, error)

Head sends a HEAD request

func (*HTTPClient) Options

func (c *HTTPClient) Options(url string, options *Options) (*Response, error)

Options sends an OPTIONS request

func (*HTTPClient) Patch

func (c *HTTPClient) Patch(url string, options *Options) (*Response, error)

Patch sends a PATCH request

func (*HTTPClient) Post

func (c *HTTPClient) Post(url string, options *Options) (*Response, error)

Post sends a POST request

func (*HTTPClient) Put

func (c *HTTPClient) Put(url string, options *Options) (*Response, error)

Put sends a PUT request

func (*HTTPClient) Request

func (c *HTTPClient) Request(ctx context.Context, method, url string, options *Options) (*Response, error)

type Multipart

type Multipart struct {
	FileName    string // Optional: not required if not a file
	ContentType string // Optional: not required if not a file
	io.Reader
}

type Options

type Options struct {
	// Header options
	Headers http.Header

	// Authentication options
	BasicAuth   *BasicAuth
	BearerToken string

	Cookies []*http.Cookie

	// Query parameters
	Query url.Values

	// Request body options
	Body      any
	JSON      any
	Form      map[string]string
	Multipart map[string]*Multipart
}

type Response

type Response struct {
	*resty.Response
}

func (*Response) Ok

func (r *Response) Ok() bool

type Transport

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

Transport implements an HTTP transport that supports both standard HTTP/HTTPS and HTTP/3 (QUIC) protocols. It handles alternative services (Alt-Svc) for protocol negotiation and connection upgrades.

func NewTransport

func NewTransport(tlsClientConfig *tls.Config, quicConfig *quic.Config) *Transport

NewTransport creates a new Transport instance with the specified TLS and QUIC configurations

func (*Transport) Close

func (t *Transport) Close() error

Close closes both the standard and HTTP/3 transports

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface. It attempts to send the request first using available alternative services, falling back to standard transport if needed

Jump to

Keyboard shortcuts

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