Documentation
¶
Overview ¶
Package crossprotect implements a middleware around cross origin resource protection.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
NewMiddleware returns a new middleware that adds cross origin protection. It silently ignore invalid origins.
Example ¶
package main
import (
"net/http"
"codeberg.org/kema/kmicro/pkg/http/middleware/crossprotect"
"codeberg.org/kema/kmicro/pkg/http/router"
)
func main() {
r := router.New()
r.Use(crossprotect.NewMiddleware())
// curl -X POST localhost:8080/
// curl -X POST -H 'Origin: evil.net' localhost:8080/
r.HandleFunc("POST /", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("Hello, World!"))
})
_ = http.ListenAndServe("[::]:8080", r.Compile())
}
Output:
Types ¶
type Option ¶
type Option func(*config)
Option configures HTTP Cross Origin Protection.
func WithDenyHandler ¶
WithDenyHandler sets handler to use for denied requests.
func WithInsecureBypassPattern ¶
WithInsecureBypassPattern sets patterns to always allow.
func WithTrustedOrigins ¶
WithTrustedOrigins sets trusted origins.
Click to show internal directories.
Click to hide internal directories.