Documentation ¶
Overview ¶
Small HTTP related utils
Index ¶
- Variables
- func CancelableServer(ctx context.Context, srv *http.Server, listener func() error) error
- func Error(w http.ResponseWriter, statusCode int)
- func NoCacheHeaders(w http.ResponseWriter)
- func RespondJSON(w http.ResponseWriter, data interface{})
- func RespondJson(w http.ResponseWriter, data interface{})deprecated
- func WrapWithErrorHandling(inner func(http.ResponseWriter, *http.Request) error) http.HandlerFunc
- type MethodMux
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // this has to be given always when making a server to mitigate slowrosis attack: // https://en.wikipedia.org/wiki/Slowloris_(computer_security) // value same as nginx: https://www.oreilly.com/library/view/nginx-http-server/9781788623551/0b1ce6c8-4863-433c-bb70-bf9aa565654c.xhtml DefaultReadHeaderTimeout = 60 * time.Second )
Functions ¶
func CancelableServer ¶
helper for adapting context cancellation to shutdown the HTTP listener
func Error ¶
func Error(w http.ResponseWriter, statusCode int)
func NoCacheHeaders ¶
func NoCacheHeaders(w http.ResponseWriter)
func RespondJSON ¶
func RespondJSON(w http.ResponseWriter, data interface{})
helper for setting JSON header and JSON-marshaling a struct into the HTTP response
func RespondJson
deprecated
func RespondJson(w http.ResponseWriter, data interface{})
Deprecated: use RespondJSON()
func WrapWithErrorHandling ¶
func WrapWithErrorHandling(inner func(http.ResponseWriter, *http.Request) error) http.HandlerFunc
creates an http.HandlerFunc wrapper of an inner func that returns an error. if an error is returned, it is responded to as an HTTP error.
Types ¶
Click to show internal directories.
Click to hide internal directories.