network

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package network provides the sandboxed HTTP client used by gbash.

This is a supported public extension package for callers that need to customize the HTTP transport, resolver, or request policy used by curl inside the sandbox. Most embedders should prefer the root `github.com/ewhauser/gbash` package and configure network access through its higher-level options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDenied

func IsDenied(err error) bool

Types

type AccessDeniedError

type AccessDeniedError struct {
	URL    string
	Reason string
}

func (*AccessDeniedError) Error

func (e *AccessDeniedError) Error() string

type Client

type Client interface {
	Do(context.Context, *Request) (*Response, error)
}

type Config

type Config struct {
	AllowedURLPrefixes []string
	AllowedMethods     []Method
	MaxRedirects       int
	Timeout            time.Duration
	MaxResponseBytes   int64
	DenyPrivateRanges  bool
}

type HTTPClient

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

func New

func New(cfg *Config, opts ...Option) (*HTTPClient, error)

func (*HTTPClient) Do

func (c *HTTPClient) Do(ctx context.Context, req *Request) (*Response, error)

type HTTPDoer

type HTTPDoer interface {
	Do(*http.Request) (*http.Response, error)
}

type InvalidConfigError

type InvalidConfigError struct {
	Problems []string
}

func (*InvalidConfigError) Error

func (e *InvalidConfigError) Error() string

type Method

type Method string
const (
	MethodGet     Method = "GET"
	MethodHead    Method = "HEAD"
	MethodPost    Method = "POST"
	MethodPut     Method = "PUT"
	MethodDelete  Method = "DELETE"
	MethodPatch   Method = "PATCH"
	MethodOptions Method = "OPTIONS"
)

type MethodNotAllowedError

type MethodNotAllowedError struct {
	Method string
}

func (*MethodNotAllowedError) Error

func (e *MethodNotAllowedError) Error() string

type Option

type Option func(*HTTPClient)

func WithDoer

func WithDoer(doer HTTPDoer) Option

func WithResolver

func WithResolver(resolver Resolver) Option

type RedirectNotAllowedError

type RedirectNotAllowedError struct {
	URL string
}

func (*RedirectNotAllowedError) Error

func (e *RedirectNotAllowedError) Error() string

type Request

type Request struct {
	Method          string
	URL             string
	Headers         map[string]string
	Body            []byte
	FollowRedirects bool
	Timeout         time.Duration
}

type Resolver

type Resolver interface {
	LookupIPAddr(context.Context, string) ([]net.IPAddr, error)
}

type Response

type Response struct {
	StatusCode int
	Status     string
	Headers    map[string]string
	Body       []byte
	URL        string
}

type ResponseTooLargeError

type ResponseTooLargeError struct {
	MaxBytes int64
}

func (*ResponseTooLargeError) Error

func (e *ResponseTooLargeError) Error() string

type TooManyRedirectsError

type TooManyRedirectsError struct {
	MaxRedirects int
}

func (*TooManyRedirectsError) Error

func (e *TooManyRedirectsError) Error() string

Jump to

Keyboard shortcuts

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