mirror of
https://github.com/kataras/iris.git
synced 2026-01-06 19:47:05 +00:00
add Context#ResetRequest and core/handlerconv.FromStdWithNext updates the request for any incoming request changes - https://github.com/kataras/iris/issues/1180
Former-commit-id: 764bf26bcaa3b7bdae0a2bdbf3bf2b6f8c5c546e
This commit is contained in:
@@ -75,6 +75,7 @@ func FromStd(handler interface{}) context.Handler {
|
||||
func FromStdWithNext(h func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)) context.Handler {
|
||||
return func(ctx context.Context) {
|
||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx.ResetRequest(r)
|
||||
ctx.Next()
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package handlerconv_test
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -42,7 +43,8 @@ func TestFromStdWithNext(t *testing.T) {
|
||||
stdWNext := func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
if username, password, ok := r.BasicAuth(); ok &&
|
||||
username == basicauth && password == basicauth {
|
||||
next.ServeHTTP(w, r)
|
||||
ctx := stdContext.WithValue(r.Context(), "key", "ok")
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
return
|
||||
}
|
||||
w.WriteHeader(iris.StatusForbidden)
|
||||
@@ -50,7 +52,7 @@ func TestFromStdWithNext(t *testing.T) {
|
||||
|
||||
h := handlerconv.FromStdWithNext(stdWNext)
|
||||
next := func(ctx context.Context) {
|
||||
ctx.WriteString(passed)
|
||||
ctx.WriteString(ctx.Request().Context().Value("key").(string))
|
||||
}
|
||||
|
||||
app := iris.New()
|
||||
|
||||
Reference in New Issue
Block a user