diff --git a/HISTORY.md b/HISTORY.md index 4a48fad0..e88fa8da 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,9 +2,13 @@ **How to upgrade**: remove your `$GOPATH/src/github.com/kataras` folder, open your command-line and execute this command: `go get -u github.com/kataras/iris/iris`. +## 4.4.8 -> 4.4.9 + +- **FIX**: Previous CORS fix wasn't enough and produces error before server's startup[*](https://github.com/kataras/iris/issues/461) if many paths were trying to auto-register an `.OPTIONS` route, now this is fixed in combined with some improvements on the [cors middleware](https://github.com/iris-contrib/middleware/tree/master/cors) too. + ## 4.4.7 -> 4.4.8 -- **NEW**: `BodyDecoder` gives the ability to set a custom decoder **per passed object** when `context.ReadJSON` and `context.ReadXML` +- **NEW**: `BodyDecoder` gives the ability to set a custom decoder **per passed object** when `context.ReadJSON` and `context.ReadXML` ```go // BodyDecoder is an interface which any struct can implement in order to customize the decode action @@ -39,7 +43,7 @@ type BodyDecoder interface { - **FIX**: CORS not worked for all http methods - **FIX**: Unexpected Party root's route slash when `DisablePathCorrection` is false(default), as reported [here](https://github.com/kataras/iris/issues/453) - **small fix**: DisablePathEscape not affects the uri string -- **small fix**: when Path Correction on POST redirect to the GET instead of POST +- **small fix**: when Path Correction on POST redirect to the GET instead of POST ## 4.4.0 -> 4.4.1 diff --git a/README.md b/README.md index d796f206..42652318 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@
-Releases +Releases Examples @@ -870,7 +870,7 @@ I recommend writing your API tests using this new library, [httpexpect](https:// Versioning ------------ -Current: **v4.4.8** +Current: **v4.4.9** > Iris is an active project @@ -906,7 +906,7 @@ This project is licensed under the [MIT License](LICENSE), Copyright (c) 2016 Ge [Travis]: http://travis-ci.org/kataras/iris [License Widget]: https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square [License]: https://github.com/kataras/iris/blob/master/LICENSE -[Release Widget]: https://img.shields.io/badge/release-4.4.8%20-blue.svg?style=flat-square +[Release Widget]: https://img.shields.io/badge/release-4.4.9%20-blue.svg?style=flat-square [Release]: https://github.com/kataras/iris/releases [Chat Widget]: https://img.shields.io/badge/community-chat%20-00BCD4.svg?style=flat-square [Chat]: https://kataras.rocket.chat/channel/iris diff --git a/http.go b/http.go index fa27e2ae..a99e9b56 100644 --- a/http.go +++ b/http.go @@ -1039,19 +1039,7 @@ func (mux *serveMux) register(method []byte, subdomain string, path string, midd // build collects all routes info and adds them to the registry in order to be served from the request handler // this happens once when server is setting the mux's handler. -func (mux *serveMux) build() func(reqCtx *fasthttp.RequestCtx) string { - - // check for cors conflicts FIRST in order to put them in OPTIONS tree also - for i := range mux.lookups { - r := mux.lookups[i] - if r.hasCors() { - if exists := mux.lookup(r.path + r.subdomain); exists == nil || exists.Method() != MethodOptions { - // skip any already registed to OPTIONS, some users maybe do that manually, so we should be careful here, we do not catch custom names but that's fairly enough - mux.register(MethodOptionsBytes, r.subdomain, r.path, r.middleware) - } - - } - } +func (mux *serveMux) build() (getRequestPath func(*fasthttp.RequestCtx) string, methodEqual func([]byte, []byte) bool) { sort.Sort(bySubdomain(mux.lookups)) @@ -1067,7 +1055,7 @@ func (mux *serveMux) build() func(reqCtx *fasthttp.RequestCtx) string { // I decide that it's better to explicit give subdomain and a path to it than registedPath(mysubdomain./something) now its: subdomain: mysubdomain., path: /something // we have different tree for each of subdomains, now you can use everything you can use with the normal paths ( before you couldn't set /any/*path) if err := tree.entry.add(r.path, r.middleware); err != nil { - mux.logger.Panic(err.Error()) + mux.logger.Panic(err) } if mp := tree.entry.paramsLen; mp > mux.maxParameters { @@ -1076,7 +1064,7 @@ func (mux *serveMux) build() func(reqCtx *fasthttp.RequestCtx) string { } // optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :) - getRequestPath := func(reqCtx *fasthttp.RequestCtx) string { + getRequestPath = func(reqCtx *fasthttp.RequestCtx) string { return utils.BytesToString(reqCtx.Path()) //string(ctx.Path()[:]) // a little bit of memory allocation, old method used: BytesToString, If I see the benchmarks get low I will change it back to old, but this way is safer. } @@ -1084,7 +1072,23 @@ func (mux *serveMux) build() func(reqCtx *fasthttp.RequestCtx) string { getRequestPath = func(reqCtx *fasthttp.RequestCtx) string { return utils.BytesToString(reqCtx.RequestURI()) } } - return getRequestPath + methodEqual = func(reqMethod []byte, treeMethod []byte) bool { + return bytes.Equal(reqMethod, treeMethod) + } + // check for cors conflicts FIRST in order to put them in OPTIONS tree also + for i := range mux.lookups { + r := mux.lookups[i] + if r.hasCors() { + // cors middleware is updated also, ref: https://github.com/kataras/iris/issues/461 + methodEqual = func(reqMethod []byte, treeMethod []byte) bool { + // preflights + return bytes.Equal(reqMethod, MethodOptionsBytes) || bytes.Equal(reqMethod, treeMethod) + } + break + } + } + + return } @@ -1101,15 +1105,16 @@ func (mux *serveMux) lookup(routeName string) *route { func (mux *serveMux) BuildHandler() HandlerFunc { // initialize the router once - getRequestPath := mux.build() + getRequestPath, methodEqual := mux.build() return func(context *Context) { routePath := getRequestPath(context.RequestCtx) for i := range mux.garden { tree := mux.garden[i] - if !bytes.Equal(tree.method, context.Method()) { + if !methodEqual(context.Method(), tree.method) { continue } + if mux.hosts && tree.subdomain != "" { // context.VirtualHost() is a slow method because it makes string.Replaces but user can understand that if subdomain then server will have some nano/or/milleseconds performance cost requestHost := context.VirtualHostname() @@ -1123,7 +1128,6 @@ func (mux *serveMux) BuildHandler() HandlerFunc { // so the host must be api.iris-go.com:8080 if tree.subdomain+mux.hostname != requestHost { // go to the next tree, we have a subdomain but it is not the correct - continue } diff --git a/iris.go b/iris.go index 69664982..3855c005 100644 --- a/iris.go +++ b/iris.go @@ -79,7 +79,7 @@ import ( const ( // Version is the current version of the Iris web framework - Version = "4.4.8" + Version = "4.4.9" banner = ` _____ _ |_ _| (_)