httprequest

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package httprequest provides portable HTTP tool request/response coordination.

Index

Constants

View Source
const Name = "http_request"

Name is the catalog name of the HTTP request tool.

Variables

This section is empty.

Functions

func Definition

func Definition() toolcontract.Definition

Definition returns the stable HTTP tool schema.

func NewHandler

func NewHandler(opts Options) toolcontract.Handler

NewHandler returns the model-facing JSON handler.

func NormalizeMethod

func NormalizeMethod(raw string) string

NormalizeMethod returns an allowed uppercase HTTP method, defaults an empty value to GET, and returns an empty string for unsupported methods.

func Register

func Register(reg toolcontract.Registrar, opts Options)

Register adds the HTTP request tool when a Host preparer is available.

func Run

func Run(ctx context.Context, request Request, opts Options) (toolcontract.Result, error)

Run executes the portable request lifecycle through the Host-owned Preparer.

Types

type HTTPDoer

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

HTTPDoer is the narrow Host-owned HTTP execution port.

type Options

type Options struct {
	Prepare      Preparer
	TimeoutMs    int
	MaxChars     int
	MaxRedirects int
	UserAgent    string
	Now          func() time.Time
}

Options configures portable request coordination.

type PrepareInput

type PrepareInput struct {
	RawURL          string
	TimeoutMs       int
	FollowRedirects bool
	MaxRedirects    int
	// CredentialSensitive asks the Host to apply its credential-safe redirect
	// policy. It does not prescribe same-origin rules or header handling.
	CredentialSensitive bool
	// OnRedirect receives display-safe redirect observations from the Host.
	// The Host remains responsible for validating every redirect before it is
	// followed. Portable retrieval uses this hook only for diagnostics.
	OnRedirect func(context.Context, string, int)
}

PrepareInput describes the policy-sensitive part of an HTTP request.

type PreparedRequest

type PreparedRequest struct {
	URL   *url.URL
	Doer  HTTPDoer
	Close func()
}

PreparedRequest contains a policy-validated URL and a Host-owned client.

type Preparer

Preparer validates the initial URL and creates a request-scoped HTTP client. Redirect validation, proxy policy and transport ownership remain in the Host.

type Request

type Request struct {
	Method          string            `json:"method,omitempty"`
	URL             string            `json:"url"`
	Headers         map[string]string `json:"headers,omitempty"`
	Query           map[string]string `json:"query,omitempty"`
	Body            string            `json:"body,omitempty"`
	TimeoutMs       int               `json:"timeout_ms,omitempty"`
	MaxChars        int               `json:"max_chars,omitempty"`
	FollowRedirects *bool             `json:"follow_redirects,omitempty"`
	MaxRedirects    int               `json:"max_redirects,omitempty"`
}

Request is the normalized request accepted by Run.

Jump to

Keyboard shortcuts

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