Update to 4.4.9

This commit is contained in:
Gerasimos Maropoulos 2016-10-09 07:47:27 +03:00
parent aa0003eb68
commit 14982891c5
4 changed files with 33 additions and 25 deletions

View File

@ -2,6 +2,10 @@
**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`

View File

@ -19,7 +19,7 @@
<br/>
<a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20version%20-%204.4.8%20-blue.svg?style=flat-square" alt="Releases"></a>
<a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20version%20-%204.4.9%20-blue.svg?style=flat-square" alt="Releases"></a>
<a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a>
@ -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

42
http.go
View File

@ -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
}

View File

@ -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 = ` _____ _
|_ _| (_)