Documentation ¶
Index ¶
- Variables
- type Option
- func WithBody(body []byte) Option
- func WithData(data []byte) Option
- func WithHeader(key, value string) Option
- func WithHeaders(headers map[string][]string) Option
- func WithMethod(method string) Option
- func WithPath(path string) Option
- func WithProto(proto string) Option
- func WithTimeout(timeout time.Duration) Option
- type Request
- func (r *Request) Bytes() []byte
- func (r *Request) Clone() Request
- func (r *Request) ContentType() string
- func (r *Request) Cookies() []*http.Cookie
- func (r *Request) EscapedBytes() []byte
- func (r *Request) HasJSONBody() bool
- func (r *Request) HasMultipartBody() bool
- func (r *Request) HasXMLBody() bool
- func (r *Request) Header(header string) string
- func (r *Request) HeaderBytes() []byte
- func (r *Request) IsEmpty() bool
- func (r *Request) MultipartForm() (*multipart.Form, error)
- func (r *Request) SetBody(body []byte)
- func (r *Request) ToJSON() ([]byte, error)
- func (r *Request) ToStdlib() (*http.Request, error)
- func (r *Request) ToStdlibWithContext(ctx context.Context) (*http.Request, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidHost is returned when building/parsing a request // from plain text and the Host line is invalid. ErrInvalidHost = errors.New("invalid host line") // ErrInvalidPayload is returned when building/parsing a request // from plain text and the payload is invalid. ErrInvalidPayload = errors.New("invalid payload") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option defines a functional option type for Request, that facilitates the construction of a Default template, but with some of the default values modified, like the HTTP method.
It can be used in combination with WithOptions.
For instance: request.WithOptions("example.org", []request.Option{request.WithMethod("POST")}).
func WithHeader ¶
WithHeader adds a new header to the default ones (see Default).
func WithHeaders ¶
WithHeaders modifies the default headers (see Default).
func WithMethod ¶
WithMethod modifies the default method (i.e. GET).
func WithTimeout ¶
WithTimeout modifies the default timeout (i.e. 20s).
type Request ¶
type Request struct { UID string // Used to detect interactions URL string Method string Path string Proto string Headers map[string][]string Body []byte Timeout time.Duration RedirectType profile.Redirect MaxRedirects int FollowedRedirects int Modifications map[string]string }
Request is a representation of an HTTP request, complementary to the standard http.Request and used here and there for scans.
func Default ¶
Default is a named constructor to instantiate a new Request with the given remote as the Request's [Request.URL].
By default, it sets the `GET` method, some basic headers, and a timeout of 20s.
func ParseRequest ¶
ParseRequest parses a request from a byte slice. If a host is given (variadic arg), it is used as the request URL.
func RequestFromJSON ¶
RequestFromJSON creates a request from a JSON byte slice.
func WithOptions ¶
WithOptions can be used to construct a Default request, but with some of the default values modified, like the HTTP method.
It can be used in combination with Option.
For instance: request.WithOptions("example.org", []request.Option{request.WithMethod("POST")}).
func (*Request) Clone ¶
Clone returns a deep copy (e.g. headers' map, and body's byte slice are also copied) of the request.
func (*Request) ContentType ¶
ContentType returns the value of the Content-Type header.
func (*Request) Cookies ¶
Cookies returns the cookies (i.e. *http.Cookie) from the request headers.
func (*Request) EscapedBytes ¶
EscapedBytes returns the request as a byte slice, with the body escaped (i.e. JSON encoded).
func (*Request) HasJSONBody ¶
HasJSONBody returns whether the request body is a valid JSON.
func (*Request) HasMultipartBody ¶
HasMultipartBody returns whether the request body is a valid multipart form.
func (*Request) HasXMLBody ¶
HasXMLBody returns whether the request body is a valid XML.
func (*Request) Header ¶
Header returns the value of the given header. If the header is not present, an empty string is returned. If the header has multiple values, the values are joined with a space.
func (*Request) HeaderBytes ¶
HeaderBytes returns the headers section as a byte slice.
func (*Request) MultipartForm ¶
MultipartForm returns the request body as a multipart form.
func (*Request) SetBody ¶
SetBody sets the request body and updates the Content-Length header accordingly.
func (*Request) ToJSON ¶
ToJSON returns the request as a JSON byte slice, with headers on its canonical form (i.e. textproto.CanonicalMIMEHeaderKey).
func (*Request) ToStdlib ¶
ToStdlib is the equivalent of Request.ToStdlibWithContext but with context.Background as the request's context.Context.
func (*Request) ToStdlibWithContext ¶
ToStdlibWithContext converts a Request to a standard library request (http.Request). Obviously, all the details that are specific to the internal request, like the unique identifier, modifications, etc. are lost in the process.