Documentation
¶
Overview ¶
Package hmiddleware contains various little bits of useful Chi style (function that takes and returns a HTTP handler) middleware for use in Heroku Go applications.
These are generic and not tied to any Heroku-specific functionality.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
CORS adds Cross-Origin Resource Sharing headers to all outgoing requests. This is known as something that is kind of hard to get right. See docs at https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS for more information.
Example ¶
r := chi.NewRouter()
r.Use(CORS)
// OR
var h http.Handler
http.ListenAndServe(":"+os.Getenv("PORT"), CORS(h))
func DisableKeepalive ¶
DisableKeepalive instructs the Go HTTP stack to close the incoming HTTP connection once all requests processed by this middleware are complete.
Example ¶
r := chi.NewRouter()
r.Use(DisableKeepalive)
// OR
var h http.Handler
http.ListenAndServe(":"+os.Getenv("PORT"), DisableKeepalive(h))
func EnsureTLS ¶
EnsureTLS ensures all incoming requests identify as having been proxied via https from the upstream reverse proxy. The way that this uses to check relies on the `X-Forwarded-Proto` header which is not defined by any formal standard. For more information on this header, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto.
Example ¶
r := chi.NewRouter()
r.Use(EnsureTLS)
// OR
var h http.Handler
http.ListenAndServe(":"+os.Getenv("PORT"), EnsureTLS(h))
Types ¶
This section is empty.