Skip to content

Commit

Permalink
feat(server): add HEAD method support (close #4740)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 11, 2023
1 parent 6887f14 commit 3f8b3da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3f8b3da

Please sign in to comment.