httputils

package
v0.0.0-...-a5f7211 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

Documentation

Overview

Small HTTP related utils

Index

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

func CancelableServer(ctx context.Context, srv *http.Server, listener func() error) error

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

type MethodMux

type MethodMux struct {
	GET    *http.ServeMux
	HEAD   *http.ServeMux
	POST   *http.ServeMux
	PUT    *http.ServeMux
	DELETE *http.ServeMux
}

when you don't want to break out gorilla/mux just to get support for routes per method..

func NewMethodMux

func NewMethodMux() *MethodMux

func (*MethodMux) ServeHTTP

func (m *MethodMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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