diff --git a/HISTORY.md b/HISTORY.md index c8e9a230..6a21f38c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -17,6 +17,64 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene **How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris` or let the automatic updater do that for you. +# Fr, 09 November 2018 | v11.0.4 + +Add `Configuration.DisablePathCorrectionRedirection` - `iris.WithoutPathCorrectionRedirection` to support +direct handler execution of the matching route without the last `'/'` instead of sending a redirect response when `DisablePathCorrection` is set to false(default behavior). + +Usage: + +For example, CORS needs the allow origin headers in redirect response as well, +however is not possible from the router to know what headers a route's handler will send to the client. +So the best option we have is to just execute the handler itself instead of sending a redirect response. +Add the `app.Run(..., iris.WithoutPathCorrectionRedirection)` on the server side if you wish +to directly fire the handler instead of redirection (which is the default behavior) +on request paths like `"$yourdomain/v1/mailer/"` when `"/v1/mailer"` route handler is registered. + +Example Code: + +```go +package main + +import "github.com/kataras/iris" + + +func main() { + app := iris.New() + + crs := func(ctx iris.Context) { + ctx.Header("Access-Control-Allow-Origin", "*") + ctx.Header("Access-Control-Allow-Credentials", "true") + ctx.Header("Access-Control-Allow-Headers", + "Access-Control-Allow-Origin,Content-Type") + ctx.Next() + } + + v1 := app.Party("/api/v1", crs).AllowMethods(iris.MethodOptions) + { + v1.Post("/mailer", func(ctx iris.Context) { + var any iris.Map + err := ctx.ReadJSON(&any) + if err != nil { + ctx.WriteString(err.Error()) + ctx.StatusCode(iris.StatusBadRequest) + return + } + ctx.Application().Logger().Infof("received %#+v", any) + }) + } + + // HERE: + app.Run(iris.Addr(":80"), iris.WithoutPathCorrectionRedirection) +} +``` + +# Tu, 06 November 2018 | v11.0.3 + +- add "part" html view engine's tmpl function: [15bb55d](https://github.com/kataras/iris/commit/15bb55d85eac378bbe0c98c10ffea938cc05fe4d) + +- update pug engine's vendor: [c20bc3b](https://github.com/kataras/iris/commit/c20bc3bceef158ef99931e609123fa0aca2a918c) + # Tu, 30 October 2018 | v11.0.2 Fix [memstore](core/memstore/memstore.go) overflows when build 32 bit app, reported and fixed by [@bouroo](https://github.com/bouroo) at: https://github.com/kataras/iris/issues/1118 diff --git a/HISTORY_GR.md b/HISTORY_GR.md index d5a4f498..c16bbf7b 100644 --- a/HISTORY_GR.md +++ b/HISTORY_GR.md @@ -17,6 +17,10 @@ **Πώς να αναβαθμίσετε**: Ανοίξτε την γραμμή εντολών σας και εκτελέστε αυτήν την εντολή: `go get -u github.com/kataras/iris` ή αφήστε το αυτόματο updater να το κάνει αυτό για σας. +# Fr, 09 November 2018 | v11.0.4 + +Πατήστε [εδώ](https://github.com/kataras/iris/blob/master/HISTORY.md#fr-09-november-2018--v1104) για να διαβάσετε στα αγγλικά τις αλλαγές που φέρνει το τελευταίο patch για την έκδοση 11. + # Tu, 30 October 2018 | v11.0.2 Πατήστε [εδώ](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-30-october-2018--v1102) για να διαβάσετε στα αγγλικά μια σημαντική διόρθωση για τα x32 machines που φέρνει το τελευταίο patch για την έκδοση 11. diff --git a/HISTORY_ID.md b/HISTORY_ID.md index 227d3a95..ed48b3a2 100644 --- a/HISTORY_ID.md +++ b/HISTORY_ID.md @@ -17,6 +17,10 @@ Developers tidak diwajibkan untuk melakukan upgrade apabila mereka tidak membutu **Cara Upgrade**: Bukan command-line anda dan eksekuis perintah ini: `go get -u github.com/kataras/iris` atau biarkan updater otomatis melakukannya untuk anda. +# Fr, 09 November 2018 | v11.0.4 + +This history entry is not translated yet to the Indonesian language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#fr-09-november-2018--v1104) instead. + # Tu, 30 October 2018 | v11.0.2 This history entry is not translated yet to the Indonesian language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-30-october-2018--v1102) instead. diff --git a/HISTORY_ZH.md b/HISTORY_ZH.md index 0666e4e5..6ad12ef6 100644 --- a/HISTORY_ZH.md +++ b/HISTORY_ZH.md @@ -17,6 +17,10 @@ **如何升级**: 打开命令行执行以下命令: `go get -u github.com/kataras/iris` 或者等待自动更新。 +# Fr, 09 November 2018 | v11.0.4 + +This history entry is not translated yet to the Chinese language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#fr-09-november-2018--v1104) instead. + # Tu, 30 October 2018 | v11.0.2 This history entry is not translated yet to the Chinese language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-30-october-2018--v1102) instead. diff --git a/README.md b/README.md index d8e4eae7..db03b61f 100644 --- a/README.md +++ b/README.md @@ -1013,7 +1013,7 @@ Iris, unlike others, is 100% compatible with the standards and that's why the ma ## Support -- [HISTORY](HISTORY.md#tu-30-october-2018--v1102) file is your best friend, it contains information about the latest features and changes +- [HISTORY](HISTORY.md#fr-09-november-2018--v1104) file is your best friend, it contains information about the latest features and changes - Did you happen to find a bug? Post it at [github issues](https://github.com/kataras/iris/issues) - Do you have any questions or need to speak with someone experienced to solve a problem at real-time? Join us to the [community chat](https://chat.iris-go.com) - Complete our form-based user experience report by clicking [here](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/README_GR.md b/README_GR.md index abe0b61d..f824e03a 100644 --- a/README_GR.md +++ b/README_GR.md @@ -108,7 +108,7 @@ _Η τελευταία ενημέρωση έγινε την [Τρίτη, 21 Νο ## Υποστήριξη -- To [HISTORY](HISTORY_GR.md#tu-30-october-2018--v1102) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές +- To [HISTORY](HISTORY_GR.md#fr-09-november-2018--v1104) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές - Μήπως τυχαίνει να βρήκατε κάποιο bug; Δημοσιεύστε το στα [github issues](https://github.com/kataras/iris/issues) - Έχετε οποιεσδήποτε ερωτήσεις ή πρέπει να μιλήσετε με κάποιον έμπειρο για την επίλυση ενός προβλήματος σε πραγματικό χρόνο; Ελάτε μαζί μας στην [συνομιλία κοινότητας](https://chat.iris-go.com) - Συμπληρώστε την αναφορά εμπειρίας χρήστη κάνοντας κλικ [εδώ](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/README_ID.md b/README_ID.md index 52586d7f..085c421c 100644 --- a/README_ID.md +++ b/README_ID.md @@ -106,7 +106,7 @@ _Diperbarui pada: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_ ## Dukungan -- File [HISTORY](HISTORY_ID.md#tu-30-october-2018--v1102) adalah sahabat anda, file tersebut memiliki informasi terkait fitur dan perubahan terbaru +- File [HISTORY](HISTORY_ID.md#fr-09-november-2018--v1104) adalah sahabat anda, file tersebut memiliki informasi terkait fitur dan perubahan terbaru - Apakah anda menemukan bug? Laporkan itu melalui [github issues](https://github.com/kataras/iris/issues) - Apakah anda memiliki pertanyaan atau butuh untuk bicara kepada seseorang yang sudah berpengalaman untuk menyelesaikan masalah secara langsung? Gabung bersama kami di [community chat](https://chat.iris-go.com) - Lengkapi laporan user-experience berbasis formulir kami dengan tekan [disini](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/README_JPN.md b/README_JPN.md index 275d30c1..151a904f 100644 --- a/README_JPN.md +++ b/README_JPN.md @@ -106,7 +106,7 @@ _Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_ ## 支援 -- [HISTORY](HISTORY.md#tu-30-october-2018--v1102)ファイルはあなたの友人です。このファイルには、機能に関する最新の情報や変更点が記載されています。 +- [HISTORY](HISTORY.md#fr-09-november-2018--v1104)ファイルはあなたの友人です。このファイルには、機能に関する最新の情報や変更点が記載されています。 - バグを発見しましたか?[github issues](https://github.com/kataras/iris/issues)に投稿をお願い致します。 - 質問がありますか?または問題を即時に解決するため、熟練者に相談する必要がありますか?[community chat](https://chat.iris-go.com)に参加しましょう。 - [here](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)をクリックしてユーザーとしての体験を報告しましょう。 diff --git a/README_PT_BR.md b/README_PT_BR.md index 4155b293..e2068d8a 100644 --- a/README_PT_BR.md +++ b/README_PT_BR.md @@ -106,7 +106,7 @@ _Atualizado em : [Terça, 21 de Novembro de 2017](_benchmarks/README_UNIX.md)_ ## Apoie -- [HISTORY](HISTORY.md#tu-30-october-2018--v1102) o arquivo HISTORY é o seu melhor amigo, ele contém informações sobre as últimas features e mudanças. +- [HISTORY](HISTORY.md#fr-09-november-2018--v1104) o arquivo HISTORY é o seu melhor amigo, ele contém informações sobre as últimas features e mudanças. - Econtrou algum bug ? Poste-o nas [issues](https://github.com/kataras/iris/issues) - Possui alguma dúvida ou gostaria de falar com alguém experiente para resolver seu problema em tempo real ? Junte-se ao [chat da nossa comunidade](https://chat.iris-go.com). - Complete nosso formulário de experiência do usuário clicando [aqui](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/README_RU.md b/README_RU.md index 3639728e..f791bb72 100644 --- a/README_RU.md +++ b/README_RU.md @@ -106,7 +106,7 @@ _Обновлено: [Вторник, 21 ноября 2017 г.](_benchmarks/READ ## Поддержка -- Файл [HISTORY](HISTORY.md#tu-30-october-2018--v1102) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях +- Файл [HISTORY](HISTORY.md#fr-09-november-2018--v1104) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях - Вы случайно обнаружили ошибку? Опубликуйте ее на [Github вопросы](https://github.com/kataras/iris/issues) - У Вас есть какие-либо вопросы или Вам нужно поговорить с кем-то, кто бы смог решить Вашу проблему в режиме реального времени? Присоединяйтесь к нам в [чате сообщества](https://chat.iris-go.com) - Заполните наш отчет о пользовательском опыте на основе формы, нажав [здесь](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/README_ZH.md b/README_ZH.md index 40dbf190..b8140b84 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -102,7 +102,7 @@ _更新于: [2017年11月21日星期二](_benchmarks/README_UNIX.md)_ ## 支持 -- [更新记录](HISTORY_ZH.md#tu-30-october-2018--v1102) 是您最好的朋友,它包含有关最新功能和更改的信息 +- [更新记录](HISTORY_ZH.md#fr-09-november-2018--v1104) 是您最好的朋友,它包含有关最新功能和更改的信息 - 你碰巧找到了一个错误? 请提交 [github issues](https://github.com/kataras/iris/issues) - 您是否有任何疑问或需要与有经验的人士交谈以实时解决问题? [加入我们的聊天](https://chat.iris-go.com) - [点击这里完成我们基于表单的用户体验报告](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) diff --git a/VERSION b/VERSION index b5faf420..6c5393d1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -11.0.2:https://github.com/kataras/iris/blob/master/HISTORY.md#tu-30-october-2018--v1102 \ No newline at end of file +11.0.4:https://github.com/kataras/iris/blob/master/HISTORY.md#fr-09-november-2018--v1104 \ No newline at end of file diff --git a/_examples/experimental-handlers/cors/simple/main.go b/_examples/experimental-handlers/cors/simple/main.go index 5ede9c44..5003329b 100644 --- a/_examples/experimental-handlers/cors/simple/main.go +++ b/_examples/experimental-handlers/cors/simple/main.go @@ -44,5 +44,11 @@ func main() { }) } - app.Run(iris.Addr(":80")) + // iris.WithoutPathCorrectionRedirection | iris#Configuration.DisablePathCorrectionRedirection: + // CORS needs the allow origin headers in the redirect response as well, we have a solution for this: + // If you use iris >= v11.0.4 then add the `app.Run(..., iris.WithoutPathCorrectionRedirection)` + // on the server side if you wish + // to directly fire the handler instead of redirection (which is the default behavior) + // on request paths like "/v1/mailer/" when "/v1/mailer" route handler is registered. + app.Run(iris.Addr(":80"), iris.WithoutPathCorrectionRedirection) } diff --git a/configuration.go b/configuration.go index 6ee8071f..e31a9c76 100644 --- a/configuration.go +++ b/configuration.go @@ -229,6 +229,14 @@ var WithoutPathCorrection = func(app *Application) { app.config.DisablePathCorrection = true } +// WithoutPathCorrectionRedirection disables the PathCorrectionRedirection setting. +// +// See `Configuration`. +var WithoutPathCorrectionRedirection = func(app *Application) { + app.config.DisablePathCorrection = false + app.config.DisablePathCorrectionRedirection = true +} + // WithoutBodyConsumptionOnUnmarshal disables BodyConsumptionOnUnmarshal setting. // // See `Configuration`. @@ -380,14 +388,24 @@ type Configuration struct { // Defaults to false. DisableInterruptHandler bool `json:"disableInterruptHandler,omitempty" yaml:"DisableInterruptHandler" toml:"DisableInterruptHandler"` - // DisablePathCorrection corrects and redirects the requested path to the registered path + // DisablePathCorrection corrects and redirects or executes directly the handler of + // the requested path to the registered path // for example, if /home/ path is requested but no handler for this Route found, // then the Router checks if /home handler exists, if yes, - // (permant)redirects the client to the correct path /home + // (permant)redirects the client to the correct path /home. + // + // See `DisablePathCorrectionRedirection` to enable direct handler execution instead of redirection. // // Defaults to false. DisablePathCorrection bool `json:"disablePathCorrection,omitempty" yaml:"DisablePathCorrection" toml:"DisablePathCorrection"` + // DisablePathCorrectionRedirection works whenever configuration.DisablePathCorrection is set to false + // and if DisablePathCorrectionRedirection set to true then it will fire the handler of the matching route without + // the last slash ("/") instead of send a redirection status. + // + // Defaults to false. + DisablePathCorrectionRedirection bool `json:"disablePathCorrectionRedirection,omitempty" yaml:"DisablePathCorrectionRedirection" toml:"DisablePathCorrectionRedirection"` + // EnablePathEscape when is true then its escapes the path, the named parameters (if any). // Change to false it if you want something like this https://github.com/kataras/iris/issues/135 to work // @@ -527,6 +545,13 @@ func (c Configuration) GetDisablePathCorrection() bool { return c.DisablePathCorrection } +// GetDisablePathCorrectionRedirection returns the Configuration#DisablePathCorrectionRedirection field. +// If DisablePathCorrectionRedirection set to true then it will fire the handler of the matching route without +// the last slash ("/") instead of send a redirection status. +func (c Configuration) GetDisablePathCorrectionRedirection() bool { + return c.DisablePathCorrectionRedirection +} + // GetEnablePathEscape is the Configuration#EnablePathEscape, // returns true when its escapes the path, the named parameters (if any). func (c Configuration) GetEnablePathEscape() bool { @@ -668,6 +693,10 @@ func WithConfiguration(c Configuration) Configurator { main.DisablePathCorrection = v } + if v := c.DisablePathCorrectionRedirection; v { + main.DisablePathCorrectionRedirection = v + } + if v := c.EnablePathEscape; v { main.EnablePathEscape = v } diff --git a/configuration_test.go b/configuration_test.go index 913ebe84..32f5bcf8 100644 --- a/configuration_test.go +++ b/configuration_test.go @@ -142,6 +142,7 @@ func TestConfigurationYAML(t *testing.T) { yamlConfigurationContents := ` DisablePathCorrection: false +DisablePathCorrectionRedirection: true EnablePathEscape: false FireMethodNotAllowed: true EnableOptimizations: true @@ -167,6 +168,10 @@ Other: t.Fatalf("error on TestConfigurationYAML: Expected DisablePathCorrection %v but got %v", expected, c.DisablePathCorrection) } + if expected := true; c.DisablePathCorrectionRedirection != expected { + t.Fatalf("error on TestConfigurationYAML: Expected DisablePathCorrectionRedirection %v but got %v", expected, c.DisablePathCorrectionRedirection) + } + if expected := false; c.EnablePathEscape != expected { t.Fatalf("error on TestConfigurationYAML: Expected EnablePathEscape %v but got %v", expected, c.EnablePathEscape) } @@ -235,6 +240,7 @@ func TestConfigurationTOML(t *testing.T) { }() tomlConfigurationContents := ` +DisablePathCorrectionRedirection = true EnablePathEscape = false FireMethodNotAllowed = true EnableOptimizations = true @@ -262,6 +268,10 @@ Charset = "UTF-8" t.Fatalf("error on TestConfigurationTOML: Expected DisablePathCorrection %v but got %v", expected, c.DisablePathCorrection) } + if expected := true; c.DisablePathCorrectionRedirection != expected { + t.Fatalf("error on TestConfigurationTOML: Expected DisablePathCorrectionRedirection %v but got %v", expected, c.DisablePathCorrectionRedirection) + } + if expected := false; c.EnablePathEscape != expected { t.Fatalf("error on TestConfigurationTOML: Expected EnablePathEscape %v but got %v", expected, c.EnablePathEscape) } diff --git a/context/configuration.go b/context/configuration.go index 20ff827f..95039516 100644 --- a/context/configuration.go +++ b/context/configuration.go @@ -20,6 +20,11 @@ type ConfigurationReadOnly interface { // (permant)redirects the client to the correct path /home. GetDisablePathCorrection() bool + // GetDisablePathCorrectionRedirection returns the Configuration#DisablePathCorrectionRedirection field. + // If DisablePathCorrectionRedirection set to true then it will fire the handler of the matching route without + // the last slash ("/") instead of send a redirection status. + GetDisablePathCorrectionRedirection() bool + // GetEnablePathEscape is the configuration.EnablePathEscape, // returns true when its escapes the path, the named parameters (if any). GetEnablePathEscape() bool diff --git a/core/router/handler.go b/core/router/handler.go index cc91819f..67ba5845 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -152,30 +152,35 @@ func (h *routerHandler) HandleRequest(ctx context.Context) { r := ctx.Request() // use Trim to ensure there is no open redirect due to two leading slashes path = "/" + strings.Trim(path, "/") - 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) + r.URL.Path = path + if !ctx.Application().ConfigurationReadOnly().GetDisablePathCorrectionRedirection() { + // do redirect, else continue with the modified path without the last "/". + 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 + // response because older user agents may not understand 301/307. + // Shouldn't send the response for POST or HEAD; that leaves GET. + if method == http.MethodGet { + note := "Moved Permanently.\n" + + ctx.ResponseWriter().WriteString(note) + } return } - ctx.Redirect(url, http.StatusMovedPermanently) - - // 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. - if method == http.MethodGet { - note := "Moved Permanently.\n" - - ctx.ResponseWriter().WriteString(note) - } - return } } diff --git a/doc.go b/doc.go index 00ab6377..9c6fe387 100644 --- a/doc.go +++ b/doc.go @@ -35,7 +35,7 @@ Source code and other details for the project are available at GitHub: Current Version -11.0.1 +11.0.4 Installation diff --git a/iris.go b/iris.go index c0ba637d..e785d016 100644 --- a/iris.go +++ b/iris.go @@ -33,7 +33,7 @@ import ( var ( // Version is the current version number of the Iris Web Framework. - Version = "11.0.1" + Version = "11.0.4" ) // HTTP status codes as registered with IANA.