From 6cc038b3b3c0f347b2837129d22da90dfe6c760c Mon Sep 17 00:00:00 2001 From: Gerasimos Maropoulos Date: Sun, 2 Oct 2016 19:35:20 +0300 Subject: [PATCH] Fix https://github.com/kataras/iris/issues/453#issuecomment-250975524 --- http.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/http.go b/http.go index 142a7817..fa42fe6c 100644 --- a/http.go +++ b/http.go @@ -3,11 +3,6 @@ package iris import ( "bytes" "crypto/tls" - "github.com/iris-contrib/letsencrypt" - "github.com/kataras/go-errors" - "github.com/kataras/iris/utils" - "github.com/valyala/fasthttp" - "github.com/valyala/fasthttp/fasthttpadaptor" "log" "net" "net/http" @@ -17,6 +12,12 @@ import ( "strings" "sync" "time" + + "github.com/iris-contrib/letsencrypt" + "github.com/kataras/go-errors" + "github.com/kataras/iris/utils" + "github.com/valyala/fasthttp" + "github.com/valyala/fasthttp/fasthttpadaptor" ) const ( @@ -1147,7 +1148,6 @@ func (mux *serveMux) BuildHandler() HandlerFunc { pathLen := len(reqPath) if pathLen > 1 { - if reqPath[pathLen-1] == '/' { reqPath = reqPath[:pathLen-1] //remove the last / } else { @@ -1157,8 +1157,12 @@ func (mux *serveMux) BuildHandler() HandlerFunc { context.Request.URI().SetPath(reqPath) urlToRedirect := utils.BytesToString(context.Request.RequestURI()) - - context.Redirect(urlToRedirect, StatusMovedPermanently) // StatusMovedPermanently + statisForRedirect := StatusMovedPermanently // StatusMovedPermanently, this document is obselte, clients caches this, so no performance difference to the next call + if bytes.Equal(tree.method, MethodPostBytes) || + bytes.Equal(tree.method, MethodPutBytes) || bytes.Equal(tree.method, MethodDeleteBytes) { + statisForRedirect = StatusTemporaryRedirect // To mantain POST data + } + context.Redirect(urlToRedirect, statisForRedirect) // RFC2616 recommends that a short note "SHOULD" be included in the // response because older user agents may not understand 301/307. // Shouldn't send the response for POST or HEAD; that leaves GET.