request

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package request contains functions to build an HTTP request from a template.

Index

Constants

View Source
const LongHelp = `` /* 406-byte string literal not displayed */

LongHelp is a text which describes how constructing a request works. It is typically used in the long help text.

Variables

View Source
var DefaultHeader = http.Header{
	"Accept":     []string{"*/*"},
	"User-Agent": []string{"monsoon"},
}

DefaultHeader contains all HTTP header values that are added by default. If the header is already present, it is not added.

Functions

func AddFlags

func AddFlags(r *Request, fs *pflag.FlagSet)

AddFlags adds flags for all options of a request to fs.

func Target

func Target(req *http.Request) (host, port string, err error)

Target returns the host and port for the request.

Types

type Header struct {
	Header http.Header
	Remove map[string]struct{} // entries are to be removed before sending the HTTP request
}

Header is an HTTP header that implements the pflag.Value interface.

func NewHeader

func NewHeader(defaults http.Header) *Header

NewHeader initializes a Header.

func (Header) Apply

func (h Header) Apply(hdr http.Header, insertValue func(string) string)

Apply applies the values in h to the target http.Header. The function insertValue is called for all names and values before adding them.

func (Header) Set

func (h Header) Set(s string) error

Set allows setting an HTTP header via options and pflag.

func (Header) String

func (h Header) String() (s string)

func (Header) Type

func (h Header) Type() string

Type returns a description string for header.

type Request

type Request struct {
	URL    string
	Method string
	Header *Header
	Body   string

	UserPass string // user:password for HTTP basic auth

	TemplateFile string // used to read the request from a file

	Names []string // these string are being replaced by a value in a specific http request

	ForceChunkedEncoding bool
	// contains filtered or unexported fields
}

Request is a template for an HTTP request.

func New

func New(names []string) *Request

New returns a new request.

func (*Request) Apply

func (r *Request) Apply(values []string) (*http.Request, error)

Apply replaces the template with value in all fields of the request and returns a new http.Request.

func (*Request) TargetURL added in v0.8.0

func (r *Request) TargetURL() (string, error)

Jump to

Keyboard shortcuts

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