parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package parser turns .http file content into httpfile.File values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsUndefinedVariableIssue added in v0.1.1

func IsUndefinedVariableIssue(issue Issue) bool

IsUndefinedVariableIssue reports whether issue is the "undefined variable" warning Resolve emits for an unresolved "{{name}}" placeholder. A caller re-resolving right before actually using a request (e.g. the CLI immediately before sending) may want to treat this as fatal even though Analyze only ever reports it as a warning (at parse/validate time, a variable that's undefined now might still be set by a script before the request is actually sent).

func Parse

func Parse(r io.Reader) (*httpfile.File, error)

Parse reads r and returns the requests it defines, or an error describing every validation error found (see Analyze for a report that also includes warnings and succeeds despite errors).

func ParseWithEnv

func ParseWithEnv(r io.Reader, envVars map[string]string) (*httpfile.File, error)

ParseWithEnv is like Parse, but merges envVars in as an extra layer of global variables: file-declared globals are the default, envVars overrides them, and a request's own local variables win over both. Pass a nil or empty envVars to get Parse's behavior.

Types

type BlockResult

type BlockResult struct {
	Index   int
	Request httpfile.Request
	Issues  []Issue
}

BlockResult is the best-effort parsed request and validation issues for one ###-delimited block.

func (BlockResult) HasErrors

func (b BlockResult) HasErrors() bool

HasErrors reports whether any issue in the block is an error.

type Issue

type Issue struct {
	Element  string // e.g. "metadata:name", "method", "url", "proto", "header"
	Severity Severity
	Message  string
}

Issue is a single validation finding for one element of a request block.

func Resolve added in v0.1.1

func Resolve(req httpfile.Request, vars map[string]string) (httpfile.Request, []Issue)

Resolve interpolates req's still-templated fields (RawURL, RawHeaders, RawBody, RawProxy) against vars, returning a copy with URL, Headers, Body, and Proxy filled in, plus any issues found while doing so (undefined variables, or a URL/proxy that still isn't absolute once resolved). Method, Proto, and every other field are copied through unchanged.

Analyze calls this once per block, using the variables known at parse time. A caller that runs scripts (the CLI's "run" command) calls it again immediately before actually sending a request, with whatever variables are current at that point -- which may include values an earlier request's post-request script just set -- so a request sees the most up-to-date variables available right before it's used, not just whatever was known when the file was first parsed.

type Result

type Result struct {
	Variables    map[string]string
	GlobalIssues []Issue
	Blocks       []BlockResult
}

Result is the outcome of analyzing an .http file: the global variables and metadata declared in the prelude (before the first "###"), any issues found there, and one BlockResult per request block, in file order.

func Analyze

func Analyze(r io.Reader) (*Result, error)

Analyze reads r and validates every request block, collecting issues instead of stopping at the first one. It only returns an error for unrecoverable problems reading r.

Content before the first "###" is the file's prelude: "key = value" lines there declare global variables, and "# @key value" lines declare global metadata, both defaults inherited by every request unless a block re-declares them locally. A file with no "###" separator at all has no prelude -- its one block is the request itself.

func AnalyzeWithEnv

func AnalyzeWithEnv(r io.Reader, envVars map[string]string) (*Result, error)

AnalyzeWithEnv is like Analyze, but merges envVars in as an extra layer of global variables between the file's own globals and each request's local variables (see ParseWithEnv for the precedence). Pass a nil or empty envVars to get Analyze's behavior.

func (Result) HasErrors

func (r Result) HasErrors() bool

HasErrors reports whether the prelude or any block has an error-level issue.

type Severity

type Severity int

Severity is how serious a validation Issue is. A Warning means the file is syntactically valid .http but relies on something httpfly doesn't act on yet (an unimplemented feature, a non-standard method, ...). An Error means the block can't be turned into a request at all.

const (
	SeverityWarning Severity = iota
	SeverityError
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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