Skip to content

Commit

Permalink
Merge pull request #108 from xushiwei/q
Browse files Browse the repository at this point in the history
yap: support builtin http HEAD impl
  • Loading branch information
xushiwei committed Mar 12, 2024
2 parents c9d0020 + 047abbd commit fa12101
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 fa12101

Please sign in to comment.