Request Handler firing twice in Go
I found an interesting gotcha today while working on a Go Project. I found that the default browser request to favicon.ico
causes that pages request handler to fire twice. To fix this, I added a route for favicon.ico
to just return as not found. Need to look into why this isn't default behavior or if Im misconfiguring my routes.
srv.mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})