Skip to content

Commit

Permalink
yap: support builtin http HEAD impl
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Mar 12, 2024
1 parent 584e94e commit 047abbd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ func (p *router) serveHTTP(w http.ResponseWriter, req *http.Request, e *Engine)
}
}
}
} else if req.Method == http.MethodHead {
p.head(w, req, e)
return
}

if req.Method == http.MethodOptions && p.HandleOPTIONS {
Expand Down Expand Up @@ -286,3 +289,16 @@ func (p *router) serveHTTP(w http.ResponseWriter, req *http.Request, e *Engine)

e.Mux.ServeHTTP(w, req)
}

func (p *router) head(w http.ResponseWriter, req *http.Request, e *Engine) {
req.Method = http.MethodGet
p.serveHTTP(&headWriter{w}, req, e)
}

type headWriter struct {
http.ResponseWriter
}

func (p *headWriter) Write(b []byte) (int, error) {
return len(b), nil
}

0 comments on commit 047abbd

Please sign in to comment.