httputil

package
v0.0.0-...-4e09bf3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is2xx

func Is2xx(statusCode int) bool

Is2xx returns true if the Status code is in the 2xx range.

func Is3xx

func Is3xx(statusCode int) bool

Is3xx returns true if the Status code is in the 3xx range.

func Is4xx

func Is4xx(statusCode int) bool

Is4xx returns true if the Status code is in the 4xx range.

func Is5xx

func Is5xx(statusCode int) bool

Is5xx returns true if the Status code is in the 5xx range.

func IsError

func IsError(statusCode int) bool

IsError returns true if the Status code is in the 4xx or 5xx range.

func IsFileRequest

func IsFileRequest(req *http.Request) bool

IsFileRequest returns true if the request is for a file instead of a page, i.e /about.

Types

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter
	Status int
	Body   *bytes.Buffer
}

ResponseRecorder is a custom response writer that captures the response body and Status code.

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder

NewResponseRecorder creates a new ResponseRecorder with the given ResponseWriter. It creates a new buffer for the response body.

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(b []byte) (int, error)

Write writes the response body to the captured buffer and the underlying ResponseWriter.

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

WriteHeader captures the Status code and writes it to the underlying ResponseWriter.

Jump to

Keyboard shortcuts

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