Documentation
¶
Overview ¶
Package httprequest provides portable HTTP tool request/response coordination.
Index ¶
- Constants
- func Definition() toolcontract.Definition
- func NewHandler(opts Options) toolcontract.Handler
- func NormalizeMethod(raw string) string
- func Register(reg toolcontract.Registrar, opts Options)
- func Run(ctx context.Context, request Request, opts Options) (toolcontract.Result, error)
- type HTTPDoer
- type Options
- type PrepareInput
- type PreparedRequest
- type Preparer
- type Request
Constants ¶
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 ¶
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.
Types ¶
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 ¶
PreparedRequest contains a policy-validated URL and a Host-owned client.
type Preparer ¶
type Preparer func(context.Context, PrepareInput) (PreparedRequest, error)
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.