From f3a14cd4bc969a5467f31f0297883bb0584c1f7e Mon Sep 17 00:00:00 2001 From: James Bayliss Date: Sun, 4 Apr 2021 22:55:14 +0100 Subject: [PATCH] web: respond to head requests --- web/load.go | 6 ++++++ web/middleware.go | 1 + web/web.go | 1 + 3 files changed, 8 insertions(+) diff --git a/web/load.go b/web/load.go index b26e1f8..303ad40 100644 --- a/web/load.go +++ b/web/load.go @@ -11,6 +11,12 @@ import ( ) func (c *Client) Load(g *gin.Context) { + // head request + if g.Request.Method == http.MethodHead { + g.Status(http.StatusOK) + return + } + // parse query b := new(fileRequest) if err := g.ShouldBindUri(b); err != nil { diff --git a/web/middleware.go b/web/middleware.go index d7bfff1..9c429af 100644 --- a/web/middleware.go +++ b/web/middleware.go @@ -13,6 +13,7 @@ func (c *Client) Logger() gin.HandlerFunc { rl := c.log.With(). Str("ip", g.ClientIP()). Str("uri", g.Request.RequestURI). + Str("method", g.Request.Method). Logger() rl.Debug().Msg("Request received") diff --git a/web/web.go b/web/web.go index b7d9aeb..eb38b38 100644 --- a/web/web.go +++ b/web/web.go @@ -45,5 +45,6 @@ func New(c *Config, uploadDirectory string) *Client { func (c *Client) SetHandlers(r *gin.Engine) { // core r.GET("/load/:hash/:filename", c.WithErrorResponse(c.Load)) + r.HEAD("/load/:hash/:filename", c.WithErrorResponse(c.Load)) r.POST("/save/:hash/:filename", c.WithErrorResponse(c.Save)) }