response

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidStatusLine is returned when the status line is invalid.
	ErrInvalidStatusLine = errors.New("invalid status line")
	// ErrInvalidStatusCode is returned when the status code is invalid.
	ErrInvalidStatusCode = errors.New("invalid status code")
	// ErrInvalidHeaders is returned when the headers are invalid.
	ErrInvalidHeaders = errors.New("invalid headers")
	// ErrUnreadableBody is returned when the body is unreadable.
	ErrUnreadableBody = errors.New("unreadable body")
)

Functions

This section is empty.

Types

type Response

type Response struct {
	Proto   string
	Code    int
	Status  string
	Headers map[string][]string
	Body    []byte
	Time    time.Duration
}

Response is a representation of an HTTP response, similar to the equivalent [request.Request] and used here and there for scans.

func FromJSON

func FromJSON(data []byte) (Response, error)

FromJSON returns a response from a JSON byte slice.

func ParseResponse

func ParseResponse(b []byte) (*Response, error)

ParseResponse parses a byte slice into a response.

func (Response) Bytes

func (r Response) Bytes() []byte

Bytes returns the response as a byte slice.

func (Response) BytesOnlyHeaders

func (r Response) BytesOnlyHeaders() []byte

BytesOnlyHeaders returns the response headers as a byte slice.

func (Response) BytesWithoutHeaders

func (r Response) BytesWithoutHeaders() []byte

BytesWithoutHeaders returns the response as a byte slice, without headers.

func (Response) ContentLength

func (r Response) ContentLength() int

ContentLength returns the length of the response. It tries to parse the Content-Length header. If the response is empty, it returns 0.

func (Response) ContentType

func (r Response) ContentType() string

ContentType returns the value of the Content-Type header. If the response is empty or the header is not set, it returns an empty string. It also removes any parameters from the header value.

func (Response) EscapedBytes

func (r Response) EscapedBytes() []byte

EscapedBytes returns the response as a byte slice, with the body escaped (i.e. JSON encoded).

func (Response) InferredType

func (r Response) InferredType() string

InferredType returns the inferred type of the response. It uses the Content-Type header to determine the type. Some types are inferred are: - HTML (text/html) - CSS (text/css) - CSV (text/csv) and many more (see [Response.mimeTypes()]).

func (Response) IsEmpty

func (r Response) IsEmpty() bool

IsEmpty returns whether the response is empty.

func (Response) Length

func (r Response) Length() int

Length returns the length of the response. If the response is empty, it returns 0. If the Content-Length header is set, it returns its value. Otherwise, it returns the length of the body.

func (Response) Location

func (r Response) Location() string

Location returns the Location header value. It concatenates multiple values with a space.

func (Response) ToJSON

func (r Response) ToJSON() ([]byte, error)

ToJSON returns the response as a JSON byte slice.

Jump to

Keyboard shortcuts

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