http

package
v0.0.0-...-c82e7e9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package http implements the host-only, single-attempt Discord HTTP boundary.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig    = errors.New("DISCORD_HTTP_INVALID_CONFIG")
	ErrInvalidRequest   = errors.New("DISCORD_HTTP_INVALID_REQUEST")
	ErrBodyTooLarge     = errors.New("DISCORD_HTTP_BODY_TOO_LARGE")
	ErrHeadersTooLarge  = errors.New("DISCORD_HTTP_HEADERS_TOO_LARGE")
	ErrResponseTooLarge = errors.New("DISCORD_HTTP_RESPONSE_TOO_LARGE")
	ErrCapacity         = errors.New("DISCORD_HTTP_CAPACITY_EXHAUSTED")
	ErrClosed           = errors.New("DISCORD_HTTP_CLOSED")
	ErrTransport        = errors.New("DISCORD_HTTP_TRANSPORT_FAILURE")
	ErrFile             = errors.New("DISCORD_HTTP_FILE_FAILURE")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	RequestDeadline     time.Duration
	JSONMaxBytes        int64
	ResponseMaxBytes    int64
	HeaderMaxBytes      int64
	RequestsPerInstance int
	RequestsPerHost     int
	RateLimitBuckets    int
	RateLimitRetention  time.Duration
}

type File

type File struct {
	Name        string
	Filename    string
	ContentType string
	Size        int64
	Open        func(context.Context) (io.ReadCloser, error)
}

Open must honor ctx; Close on its result must interrupt an ongoing Read. The caller retains its source lease until Do has returned.

type Request

type Request struct {
	Owner         string
	Method        string
	Path          string
	Query         url.Values
	Bucket        string
	Authorization string
	AuditReason   *string
	Locale        *string
	JSON          []byte
	Files         []File
	MaxBodyBytes  int64
}

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       []byte
	Dispatched bool
}

type Transport

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

func New

func New(config Config, client *http.Client) (*Transport, error)

New copies the trusted client; redirects and transparent replay are disabled. A standard Transport is cloned so its response-header and connection bounds do not mutate the caller's transport. A custom RoundTripper must itself honor request cancellation and enforce bounded header parsing before returning.

func (*Transport) Close

func (t *Transport) Close() error

Close cancels and joins all calls, including admission waits and producers.

func (*Transport) Do

func (t *Transport) Do(ctx context.Context, request Request) (result Response, err error)

Do makes exactly one attempt. Non-2xx responses are returned without a Go error for host-side typed projection; no remote body or URL appears in errors.

Jump to

Keyboard shortcuts

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