request

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedBodyType = errors.New("unsupported body type")

Functions

This section is empty.

Types

type FileField

type FileField struct {
	// Fieldname is the name of the field
	Fieldname string
	// Filename is the name of the file
	Filename string
	// Source is the path to the file
	Source string
	// Body is the content of the file
	Body any
}

FileField represents a file field data for one file

func (*FileField) Write

func (f *FileField) Write(w *multipart.Writer) (err error)

Write writes the file field to the multipart writer

type Request

type Request struct {
	// Ctx is the context of the request
	Ctx context.Context
	// Method is the HTTP method. Default is GET
	Method string
	// Header is the HTTP headers
	Header http.Header
	// Body is the raw request body
	Body []byte
	// Form is the form data that will be encoded as application/x-www-form-urlencoded
	Form url.Values
	// Params is the query parameters
	Params url.Values
	// Files represents the files that will be sent in the request's body as multipart/form-data
	Files []*FileField
	// Cookies is the cookies that will be sent in the request
	Cookies []*http.Cookie
	// URL is the URL of the request
	URL *url.URL
	// Trace is a flag that indicates if the request should be traced
	Trace bool
	// JSON is a entity to be sent as JSON
	JSON any
	// contains filtered or unexported fields
}

Request represents a wrapper around http.Request

func NewRequest

func NewRequest(ctx context.Context, dstURL string, opts ...RequestOption) *Request

NewRequest creates a new wrapped request with options

func (*Request) IntoHttpRequest

func (r *Request) IntoHttpRequest() (req *http.Request, err error)

IntoHttpRequest converts the request to http.Request

func (*Request) TraceInfo

func (r *Request) TraceInfo() *TraceInfo

TraceInfo represents the trace information of the request. Available only if the request is traced.

type RequestOption

type RequestOption func(*Request)

RequestOption is a function that modifies the request

type TLSHandshake

type TLSHandshake struct {
	State tls.ConnectionState
	Error error
}

TLSHandshake represents a TLS handshake

type TraceConnect

type TraceConnect struct {
	Network string
	Address string
	Error   error
	Time    time.Time
}

TraceConnect represents a connection trace

type TraceInfo

type TraceInfo struct {
	Timings      TraceTimings
	GetConnHost  string
	GotConn      httptrace.GotConnInfo
	DNSDone      httptrace.DNSDoneInfo
	DNSStart     httptrace.DNSStartInfo
	WroteRequest httptrace.WroteRequestInfo
	PutIdleError error
	ConnectStart []TraceConnect
	ConnectDone  []TraceConnect
}

TraceInfo represents the trace information

type TraceTimings

type TraceTimings struct {
	ConnGet           time.Time
	ConnGot           time.Time
	PutIdleConn       time.Time
	DNSStart          time.Time
	DNSDone           time.Time
	ConnectStart      time.Time
	ConnectDone       time.Time
	TLSHandshakeStart time.Time
	TLSHandshakeDone  time.Time
	FirstByte         time.Time
	Wait100Continue   time.Time
	WroteHeaders      time.Time
	WroteRequest      time.Time
}

TraceTimings represents the timings of the request

Jump to

Keyboard shortcuts

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