request

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeaderPairs

func HeaderPairs(headersRaw string) [][2]string

HeaderPairs splits raw header lines into name/value pairs, preserving the raw (unresolved) values and the order they appear in.

func SplitEssentials

func SplitEssentials(essentialsRaw string) (method, rawURL, proto string)

SplitEssentials splits a raw request line into method, URL, and protocol without parsing the URL, so {{placeholders}} stay intact. The method defaults to GET like parseEssentials.

Types

type Directives

type Directives struct {
	NoRedirect  bool
	NoCookieJar bool
	NoLog       bool
	Timeout     time.Duration
	Vegeta      *VegetaDirective
}

Directives are per-request execution options set via `# @...` comments.

type File

type File struct {
	Vars      map[string]string
	Templates []*Template
}

File is the parsed form of one .http file: in-file variables plus one request template per `###`-separated block.

func ParseFile

func ParseFile(content string) (*File, error)

ParseFile splits .http content into request templates without resolving any placeholders. `@name = value` lines outside request blocks become file variables; `# @...` comment lines before the request line become the template's name and directives.

type FormField

type FormField struct {
	Name        string
	ContentType string
	Headers     textproto.MIMEHeader
	Filename    string
	Content     io.Reader
}

func (FormField) Encode

func (f FormField) Encode(w *multipart.Writer) error

type Rate

type Rate struct {
	Freq int
	Per  time.Duration
}

Rate is a request frequency per time unit, e.g. 50/s.

type Script

type Script struct {
	Code string
	Path string
}

Script is a pre-request or response handler script: inline `{% ... %}` code, or a path to a .js file relative to the .http file.

func (Script) Empty

func (s Script) Empty() bool

type Template

type Template struct {
	Name       string
	Directives Directives
	Essentials string
	HeadersRaw string
	BodyRaw    string
	PreScript  Script
	PostScript Script
}

Template is a single request block with its raw sections still containing {{placeholders}}. Resolution happens at Build time, just before sending, so later requests can use variables produced by earlier responses. Scripts are never resolved — {{ }} inside script source stays untouched.

func (*Template) Build

func (t *Template) Build(resolve func(string) string, wd string) (*http.Request, error)

Build resolves placeholders in the template's sections and constructs the *http.Request. wd is the directory file includes resolve against.

func (*Template) BuildGRPC

func (t *Template) BuildGRPC(resolve func(string) string) (rawURL string, headers [][2]string, body string)

BuildGRPC resolves the template's sections for a gRPC send: the raw target URL, the header pairs (future metadata), and the JSON body. Like Build, resolution happens here at send time so request chaining works.

func (*Template) IsGRPC

func (t *Template) IsGRPC() bool

IsGRPC reports whether the request line's method is GRPC.

type VegetaDirective

type VegetaDirective struct {
	Rate        Rate
	Duration    time.Duration
	Workers     uint64
	MaxWorkers  uint64
	Connections int
	MaxBody     int64
}

VegetaDirective is the load profile declared by `# @vegeta` on a request block. Zero Workers/MaxWorkers/Connections leave the attacker defaults.

Jump to

Keyboard shortcuts

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