Browse Source

Respond to HEAD

DarthSim 5 years ago
parent
commit
aa8cff62f4
2 changed files with 7 additions and 2 deletions
  1. 4 0
      router.go
  2. 3 2
      server.go

+ 4 - 0
router.go

@@ -64,6 +64,10 @@ func (r *router) OPTIONS(prefix string, handler routeHandler, exact bool) {
 	r.Add(http.MethodOptions, prefix, handler, exact)
 }
 
+func (r *router) HEAD(prefix string, handler routeHandler, exact bool) {
+	r.Add(http.MethodHead, prefix, handler, exact)
+}
+
 func (r *router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
 	req = req.WithContext(setTimerSince(req.Context()))
 

+ 3 - 2
server.go

@@ -25,7 +25,8 @@ func buildRouter() *router {
 	r.GET("/health", handleHealth, true)
 	r.GET("/favicon.ico", handleFavicon, true)
 	r.GET("/", withCORS(withSecret(handleProcessing)), false)
-	r.OPTIONS("/", withCORS(handleOptions), false)
+	r.HEAD("/", withCORS(handleHead), false)
+	r.OPTIONS("/", withCORS(handleHead), false)
 
 	return r
 }
@@ -128,7 +129,7 @@ func handleHealth(reqID string, rw http.ResponseWriter, r *http.Request) {
 	rw.Write(imgproxyIsRunningMsg)
 }
 
-func handleOptions(reqID string, rw http.ResponseWriter, r *http.Request) {
+func handleHead(reqID string, rw http.ResponseWriter, r *http.Request) {
 	logResponse(reqID, r, 200, nil, nil, nil)
 	rw.WriteHeader(200)
 }