mirror of https://github.com/Xhofe/alist
feat(server): add `HEAD` method support (close #4740)
parent
6887f14ec6
commit
3f8b3da52b
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue