http

package
v0.1.1112 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultHTTPClient added in v0.1.559

func NewDefaultHTTPClient() (*http.Client, error)

NewDefaultHTTPClient returns a properly configured *http.Client with permissive timeouts for large file uploads and long-lived connections (e.g., WebSocket handshakes). Timeouts are controlled by the provided context in the calling code.

Types

type Client

type Client interface {
	Blackbox
	contract.HTTPOperator
}

func NewClient

func NewClient(d Dependencies, opts ClientOptions) (Client, error)

type ClientOption added in v0.1.14

type ClientOption = contract.Opt[ClientOptions]

func WithServeFileFS added in v0.1.896

func WithServeFileFS(x fs.FS) ClientOption

func WithTimeout added in v0.1.14

func WithTimeout(x time.Duration) ClientOption

type ClientOptions added in v0.1.14

type ClientOptions struct {
	Timeout     time.Duration
	ServeFileFS fs.FS
}

func ApplyClientOptions added in v0.1.14

func ApplyClientOptions(opts *ClientOptions, modifiers ...ClientOption) ClientOptions

type DefaultTool added in v0.1.11

type DefaultTool struct {
	T *contract.Tool[Client]
}

func NewTool

func NewTool(c Client, opts contract.ToolOptions[Client]) *DefaultTool

func (*DefaultTool) CopyHeaders added in v0.1.11

func (d *DefaultTool) CopyHeaders(ctx context.Context, dst, src *http.Request, headers ...string) error

CopyHeaders copies the specified headers from the source request to the destination request. If no headers are specified, all headers from the source request will be copied to the destination request.

func (*DefaultTool) DecodeBody added in v0.1.11

func (d *DefaultTool) DecodeBody(ctx context.Context, r *http.Request, v any) error

DecodeBody reads and unmarshals the request body into the provided variable.

func (*DefaultTool) Do added in v0.1.11

Do sends an HTTP request and returns an HTTP response.

func (*DefaultTool) DoWithTimeout added in v0.1.552

func (d *DefaultTool) DoWithTimeout(ctx context.Context, r *http.Request, t time.Duration) (*http.Response, error)

DoWithTimeout sends an HTTP request and returns an HTTP response bypassing the default timeout.

func (*DefaultTool) GetHeaders added in v0.1.11

func (d *DefaultTool) GetHeaders(ctx context.Context, r *http.Request) (http.Header, error)

GetHeaders extracts and returns all headers from an HTTP request as an http.Header map.

func (*DefaultTool) NewRequest added in v0.1.11

func (d *DefaultTool) NewRequest(ctx context.Context, method, url string, opts contract.RequestOptions) (*http.Request, error)

NewRequest creates a new HTTP request with the specified method, URL, and options.

func (*DefaultTool) OpenFile added in v0.1.377

func (d *DefaultTool) OpenFile(ctx context.Context, fsys http.FileSystem, name string) (http.File, error)

OpenFile attempts to open a file.

func (*DefaultTool) ParseForm added in v0.1.796

func (d *DefaultTool) ParseForm(ctx context.Context, r *http.Request) error

ParseForm parses form data.

func (*DefaultTool) QueryString added in v0.1.11

func (d *DefaultTool) QueryString(ctx context.Context, pairs ...string) (string, error)

QueryString constructs a query parameter string from a variadic number of key-value pairs. The values passed should not already be URL-escaped, as the function will handle escaping.

func (*DefaultTool) RespondJSON added in v0.1.11

func (d *DefaultTool) RespondJSON(ctx context.Context, w http.ResponseWriter, v any, status int, escapeHTML bool) error

RespondJSON writes the JSON data to the response writer with appropriate headers. The Content-Type header is set to application/json. The Content-Length header is set with the length of the uncompressed data. The Content-Length is not set if the Content-Encoding header is set to gzip. The status code is set based on the provided code parameter.

func (*DefaultTool) ServeContent added in v0.1.1022

func (d *DefaultTool) ServeContent(ctx context.Context, opts contract.ServeContentOptions) error

ServeContent serves content.

func (*DefaultTool) ServeFile added in v0.1.377

func (d *DefaultTool) ServeFile(ctx context.Context, opts contract.ServeFileOptions) error

ServeFile serves a static file.

func (*DefaultTool) ServeHTML added in v0.1.11

func (d *DefaultTool) ServeHTML(ctx context.Context, w http.ResponseWriter, body io.Reader, status int) error

ServeHTML writes an HTML response to the provided http.ResponseWriter with the given HTML content and HTTP status code.

func (*DefaultTool) SetQueryParams added in v0.1.326

func (d *DefaultTool) SetQueryParams(ctx context.Context, r *http.Request, q map[string][]string, override bool) error

SetQueryParams updates or appends query parameters.

func (*DefaultTool) ValidateQueryParams added in v0.1.11

func (d *DefaultTool) ValidateQueryParams(ctx context.Context, q map[string][]string, rules ...contract.QueryParamRule) error

ValidateQueryParams ...

func (*DefaultTool) Write added in v0.1.377

func (d *DefaultTool) Write(ctx context.Context, w http.ResponseWriter, b []byte) (int, error)

Write writes bytes to response.

type Dependencies added in v0.1.8

type Tool added in v0.1.245

type Tool interface {
	Client
}

Jump to

Keyboard shortcuts

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