Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Convert again in case request may modify by mw
Browse files Browse the repository at this point in the history
  • Loading branch information
arsmn committed Dec 2, 2020
1 parent 158e558 commit 1b641c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ func HTTPHandler(h http.Handler) fiber.Handler {
func HTTPMiddleware(mw func(http.Handler) http.Handler) fiber.Handler {
return func(c *fiber.Ctx) error {
var next bool
nextHandler := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { next = true })
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next = true
// Convert again in case request may modify by middleware
c.Request().Header.SetMethod(r.Method)
c.Request().SetRequestURI(r.RequestURI)
c.Request().SetHost(r.Host)
for key, val := range r.Header {
for _, v := range val {
c.Request().Header.Set(key, v)
}
}
})
_ = HTTPHandler(mw(nextHandler))(c)
if next {
return c.Next()
Expand Down

0 comments on commit 1b641c6

Please sign in to comment.