Documentation ¶
Index ¶
- Variables
- type Response
- func (r Response) Bytes() []byte
- func (r Response) BytesOnlyHeaders() []byte
- func (r Response) BytesWithoutHeaders() []byte
- func (r Response) ContentLength() int
- func (r Response) ContentType() string
- func (r Response) EscapedBytes() []byte
- func (r Response) InferredType() string
- func (r Response) IsEmpty() bool
- func (r Response) Length() int
- func (r Response) Location() string
- func (r Response) ToJSON() ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
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 ConnTime time.Duration }
Response is a representation of an HTTP response, similar to the equivalent [request.Request] and used here and there for scans.
func FromStdlib ¶
FromStdlib converts a Response to a standard library response (http.Response). Obviously, not all the details (like the duration) can be filled from the info the standard response contains.
The http.Response.Body is read, but then reset with io.NopCloser.
func ParseResponse ¶
ParseResponse parses a byte slice into a response.
func (Response) BytesOnlyHeaders ¶
BytesOnlyHeaders returns the response headers as a byte slice.
func (Response) BytesWithoutHeaders ¶
BytesWithoutHeaders returns the response as a byte slice, without headers.
func (Response) ContentLength ¶
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 ¶
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 ¶
EscapedBytes returns the response as a byte slice, with the body escaped (i.e. JSON encoded).
func (Response) InferredType ¶
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) Length ¶
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.