From 1165b4527a1f1c9fed72b43bbf31e9ee75fe12fd Mon Sep 17 00:00:00 2001 From: Gerasimos Maropoulos Date: Thu, 8 Mar 2018 20:55:58 +0200 Subject: [PATCH] fix https://github.com/kataras/iris/issues/921 Former-commit-id: f8560514a7b48f83121ddd21d74b4016af4e1b67 --- configuration_test.go | 2 +- core/router/handler.go | 8 ++++++++ sessions/sessiondb/redis/service/service.go | 7 +++---- view/handlebars.go | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/configuration_test.go b/configuration_test.go index f5aed4f7..61915011 100644 --- a/configuration_test.go +++ b/configuration_test.go @@ -30,7 +30,7 @@ func TestConfigurationStatic(t *testing.T) { afterNew = *app.config - if app.config.DisableBodyConsumptionOnUnmarshal == false { + if !app.config.DisableBodyConsumptionOnUnmarshal { t.Fatalf("Passing a Configuration field as Option fails, expected DisableBodyConsumptionOnUnmarshal to be true but was false") } diff --git a/core/router/handler.go b/core/router/handler.go index 18501b39..b9b79202 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -172,6 +172,14 @@ func (h *routerHandler) HandleRequest(ctx context.Context) { r.URL.Path = path url := r.URL.String() + // Fixes https://github.com/kataras/iris/issues/921 + // This is caused for security reasons, imagine a payment shop, + // you can't just permantly redirect a POST request, so just 307 (RFC 7231, 6.4.7). + if method == http.MethodPost || method == http.MethodPut { + ctx.Redirect(url, http.StatusTemporaryRedirect) + return + } + ctx.Redirect(url, http.StatusMovedPermanently) // RFC2616 recommends that a short note "SHOULD" be included in the diff --git a/sessions/sessiondb/redis/service/service.go b/sessions/sessiondb/redis/service/service.go index e48e63de..34d4f8db 100644 --- a/sessions/sessiondb/redis/service/service.go +++ b/sessions/sessiondb/redis/service/service.go @@ -128,10 +128,9 @@ func (r *Service) GetBytes(key string) ([]byte, error) { func (r *Service) Delete(key string) error { c := r.pool.Get() defer c.Close() - if _, err := c.Do("DEL", r.Config.Prefix+key); err != nil { - return err - } - return nil + + _, err := c.Do("DEL", r.Config.Prefix+key) + return err } func dial(network string, addr string, pass string) (redis.Conn, error) { diff --git a/view/handlebars.go b/view/handlebars.go index bfede2be..68b1fcee 100644 --- a/view/handlebars.go +++ b/view/handlebars.go @@ -128,7 +128,7 @@ func (s *HandlebarsEngine) loadDirectory() error { // instead of the html/template engine which works like {{ render "myfile.html"}} and accepts the parent binding, with handlebars we can't do that because of lack of runtime helpers (dublicate error) var templateErr error - filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + filepath.Walk(dir, func(path string, info os.FileInfo, _ error) error { if info == nil || info.IsDir() { return nil }