prerequest

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(req *restfile.Request, out Output) error

Apply copies script and patch values to req without expanding placeholders. It marks written fields so later template expansion leaves them unchanged.

func Normalize

func Normalize(out *Output)

func SetRequestVars added in v1.0.0

func SetRequestVars(req *restfile.Request, variables vars.NameMap[string])

SetRequestVars merges script writes into request-scoped variables. Names are matched case-insensitively after trimming whitespace. New variables are appended in deterministic order.

Types

type ExpandFunc added in v1.11.0

type ExpandFunc func(text string, set vars.NameMap[string]) (string, error)

ExpandFunc renders an authored request value as a script reads it. Variables and expressions see the script's own writes in set.

func (ExpandFunc) Bind added in v1.11.0

func (f ExpandFunc) Bind(set *vars.NameMap[string]) func(string) (string, error)

Bind returns f for a host that keeps its writes in set. set is read on each call, so later writes are seen. A nil f binds to nil.

type Input

type Input struct {
	Request   *restfile.Request
	Variables map[string]string
	Globals   vars.Globals
	BaseDir   string
	Context   context.Context
	Secrets   *vars.Secrets
	// Expand renders the authored values the script reads. A nil Expand shows
	// them as written.
	Expand ExpandFunc
}

Input is the host state available to a pre-request script runner.

type Literal added in v1.12.0

type Literal struct {
	Start, End int
	Text, Hint string
}

func Literals added in v1.12.0

func Literals(text string) []Literal

Literals finds placeholders that will be sent unchanged.

type Output

type Output struct {
	Headers http.Header
	// Removals are tracked separately because headers declared in the file are
	// not part of Headers and would otherwise survive the script.
	HeaderDels map[string]struct{}
	// Query values are set, or removed when nil.
	Query  map[string]*string
	Body   *string
	URL    *string
	Method *string
	// Variables contains script writes, normalized to one entry per name.
	Variables vars.NameMap[string]
	Globals   vars.Globals
	// contains filtered or unexported fields
}

Output is a set of request changes from pre-request scripts or @apply patches.

func (*Output) AddHeader added in v1.0.0

func (o *Output) AddHeader(at diag.Pos, name, value string)

func (*Output) DelHeader added in v1.0.0

func (o *Output) DelHeader(name string)

func (*Output) SetBody added in v1.12.0

func (o *Output) SetBody(at diag.Pos, value string)

func (*Output) SetHeader added in v1.0.0

func (o *Output) SetHeader(at diag.Pos, name, value string)

func (*Output) SetQuery added in v1.0.0

func (o *Output) SetQuery(at diag.Pos, name, value string)

func (*Output) SetURL added in v1.12.0

func (o *Output) SetURL(at diag.Pos, value string)

func (*Output) Warnings added in v1.12.0

func (o *Output) Warnings() []string

Warnings returns warnings in script order, leaving out replaced or deleted values.

Jump to

Keyboard shortcuts

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