feat(server): add `HEAD` method support (close #4740)

pull/4745/head
Andy Hsu 2023-07-11 13:47:49 +08:00
parent 6887f14ec6
commit 3f8b3da52b
2 changed files with 11 additions and 0 deletions

View File

@ -58,6 +58,9 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
} else {
w.WriteHeader(link.Status)
}
if r.Method == http.MethodHead {
return nil
}
_, err = io.Copy(w, link.Data)
if err != nil {
return err
@ -95,6 +98,9 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
} else {
w.WriteHeader(link.Status)
}
if r.Method == http.MethodHead {
return nil
}
return link.Writer(w)
} else {
req, err := http.NewRequest(r.Method, link.URL, nil)
@ -132,6 +138,9 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
log.Debugln(msg)
return errors.New(msg)
}
if r.Method == http.MethodHead {
return nil
}
_, err = io.Copy(w, res.Body)
if err != nil {
return err

View File

@ -39,6 +39,8 @@ func Init(e *gin.Engine) {
g.GET("/d/*path", middlewares.Down, handles.Down)
g.GET("/p/*path", middlewares.Down, handles.Proxy)
g.HEAD("/d/*path", middlewares.Down, handles.Down)
g.HEAD("/p/*path", middlewares.Down, handles.Proxy)
api := g.Group("/api")
auth := api.Group("", middlewares.Auth)