http

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout bounds a request when the step does not set `timeout`. The zero value of http.Client means "wait forever", which lets a single unresponsive endpoint hold a workflow open until the step timeout fires.

View Source
const DefaultTraceHeader = "X-Probe-Trace"

DefaultTraceHeader is the header trace_header: true sends.

Variables

This section is empty.

Functions

func MarshalBodyIfJSON

func MarshalBodyIfJSON(data, m map[string]any)

MarshalBodyIfJSON converts body to JSON string when Content-Type is application/json Supports map[string]any and []any body types

func Request

func Request(data map[string]any, opts ...Option) (map[string]any, error)

func RequestStep

func RequestStep(call actionrpc.Call, opts ...Option) (map[string]any, map[string]any, error)

RequestStep is Request for a step, with the state the action keeps in a job. When keep_cookies is true, the cookies kept in the state are sent, and the state returned keeps those the server set as well; otherwise the state returned is nil, which leaves the job's state as it was. When trace_header is given, the request carries a header that names the run, job and step.

func ResolveMethodAndURL

func ResolveMethodAndURL(data map[string]any) error

ResolveMethodAndURL resolves HTTP method fields and updates the data map Converts method fields like "get", "post" to "method" and "url" fields

func Spec added in v1.30.0

func Spec() actionspec.Spec

Spec declares the http action. It keeps to every kind of guard: it sends only GET, HEAD and OPTIONS under read-only, and connects only to a host the guard allows, redirects included. openapi, an OpenAPI document, asks it to check a step against the document. Its req holds, besides the fields of Req, multipart, for a request that sends one, which may hold anything; its res holds, besides the fields of Res, violations and contract, for a response checked against an OpenAPI document.

Types

type Action

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

func (*Action) Run

func (a *Action) Run(with map[string]any) (map[string]any, error)

func (*Action) RunStep

func (a *Action) RunStep(call actionrpc.Call) (map[string]any, map[string]any, error)

RunStep runs the request for a step: with the cookies the job keeps, when the step asks for keep_cookies, returning the cookies to keep, and with a header that names the step, when it asks for trace_header.

type Callback

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

type Option

type Option func(*Callback)

func WithAfter

func WithAfter(f func(res *hp.Response)) Option

func WithBefore

func WithBefore(f func(req *hp.Request)) Option

type Req

type Req struct {
	URL     string            `map:"url" validate:"required"`
	Method  string            `map:"method" validate:"required"`
	Header  map[string]string `map:"headers"`
	Body    string            `map:"body"` // Changed from []byte to string for text data
	Timeout string            `map:"timeout"`
	// contains filtered or unexported fields
}

func NewReq

func NewReq() *Req

func (*Req) Do

func (r *Req) Do() (*Result, error)

type Res

type Res struct {
	Status   string            `map:"status"`
	Code     int               `map:"code"`
	Header   map[string]string `map:"headers"`
	Body     string            `map:"body"`     // Changed from []byte to string for text data
	FilePath string            `map:"filepath"` // New field for binary file paths
	// Cookies holds the names and values of the cookies the server set, on
	// redirects included.
	Cookies map[string]string `map:"cookies"`
}

type Result

type Result struct {
	Req    Req           `map:"req"`
	Res    Res           `map:"res"`
	RT     time.Duration `map:"rt"`
	Status int           `map:"status"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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