GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — interpose/examples/nosurf/main.go at master · carbocation/interpose Expand file tree/ Copy pathmain.goMore file actions 57 lines (47 loc) · 1.24 KB / Copy pathmain.goFile metadata and controls57 lines (47 loc) · 1.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 package main import ( "html/template" "net/http" "time" "github.com/carbocation/interpose" "github.com/carbocation/interpose/middleware" "github.com/gorilla/mux" "github.com/justinas/nosurf" "github.com/stretchr/graceful" ) var templ = template.Must(template.New("t1").Parse(` <!doctype html> <html> <body> {{ if .name }} <p>Your name: {{ .name }}</p> {{ end }} <form action="/" method="POST"> <input type="text" name="name"> <!-- Try removing this or changing its value and see what happens --> <input type="hidden" name="csrf_token" value="{{ .token }}"> <input type="submit" value="Send"> </form> </body> </html> `)) func main() { mw := interpose.New() // Invoke NoSurf (it modifies headers so must be called before your router) mw.Use(middleware.Nosurf()) // Create and apply the router router := mux.NewRouter() mw.UseHandler(router) router.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { context := make(map[string]string) context["token"] = nosurf.Token(req) if req.Method == "POST" { context["name"] = req.FormValue("name") } templ.Execute(w, context) }) // Launch and permit graceful shutdown, allowing up to 10 seconds for existing // connections to end graceful.Run(":3001", 10*time.Second, mw) } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |