mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
parent
dd72a1e398
commit
38b0a796bd
|
@ -371,6 +371,8 @@ Other Improvements:
|
||||||
|
|
||||||
![DBUG routes](https://iris-go.com/images/v12.2.0-dbug2.png?v=0)
|
![DBUG routes](https://iris-go.com/images/v12.2.0-dbug2.png?v=0)
|
||||||
|
|
||||||
|
- Fix [#1552](https://github.com/kataras/iris/issues/1552).
|
||||||
|
|
||||||
- Proper listing of root directories on `Party.HandleDir` when its `DirOptions.ShowList` was set to true.
|
- Proper listing of root directories on `Party.HandleDir` when its `DirOptions.ShowList` was set to true.
|
||||||
|
|
||||||
- Socket Sharding as requested at [#1544](https://github.com/kataras/iris/issues/1544). New `iris.WithSocketSharding` Configurator and `SocketSharding bool` setting.
|
- Socket Sharding as requested at [#1544](https://github.com/kataras/iris/issues/1544). New `iris.WithSocketSharding` Configurator and `SocketSharding bool` setting.
|
||||||
|
@ -422,6 +424,7 @@ Other Improvements:
|
||||||
New Package-level Variables:
|
New Package-level Variables:
|
||||||
|
|
||||||
- `iris.DirListRich` to override the default look and feel if the `DirOptions.ShowList` was set to true, can be passed to `DirOptions.DirList` field.
|
- `iris.DirListRich` to override the default look and feel if the `DirOptions.ShowList` was set to true, can be passed to `DirOptions.DirList` field.
|
||||||
|
- `iris.DirListRichOptions` to pass on `iris.DirListRich` method.
|
||||||
- `iris.ErrGzipNotSupported` to export the `context.ErrGzipNotSupported` when trying to write gzip but client does not support.
|
- `iris.ErrGzipNotSupported` to export the `context.ErrGzipNotSupported` when trying to write gzip but client does not support.
|
||||||
- `iris.GzipReader` middleware to decode gzip requests on next read actions.
|
- `iris.GzipReader` middleware to decode gzip requests on next read actions.
|
||||||
- `iris.B, KB, MB, GB, TB, PB, EB` for byte units.
|
- `iris.B, KB, MB, GB, TB, PB, EB` for byte units.
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (b *Broker) ServeHTTP(ctx iris.Context) {
|
||||||
b.newClients <- messageChan
|
b.newClients <- messageChan
|
||||||
|
|
||||||
// Listen to connection close and when the entire request handler chain exits(this handler here) and un-register messageChan.
|
// Listen to connection close and when the entire request handler chain exits(this handler here) and un-register messageChan.
|
||||||
ctx.OnClose(func() {
|
ctx.OnClose(func(iris.Context) {
|
||||||
// Remove this client from the map of connected clients
|
// Remove this client from the map of connected clients
|
||||||
// when this handler exits.
|
// when this handler exits.
|
||||||
b.closingClients <- messageChan
|
b.closingClients <- messageChan
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package main // #1552
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := newApp()
|
||||||
|
app.Listen(":8080")
|
||||||
|
}
|
||||||
|
|
||||||
|
func newApp() *iris.Application {
|
||||||
|
app := iris.New()
|
||||||
|
|
||||||
|
app.UseGlobal(middleware("first"))
|
||||||
|
app.UseGlobal(middleware("second"))
|
||||||
|
app.DoneGlobal(onDone)
|
||||||
|
|
||||||
|
app.Get("/{name prefix(one)}", handler("first route"))
|
||||||
|
app.Get("/{name prefix(two)}", handler("second route"))
|
||||||
|
app.Get("/{name prefix(three)}", handler("third route"))
|
||||||
|
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
func middleware(str string) iris.Handler {
|
||||||
|
return func(ctx iris.Context) {
|
||||||
|
ctx.Writef("Called %s middleware\n", str)
|
||||||
|
ctx.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handler(str string) iris.Handler {
|
||||||
|
return func(ctx iris.Context) {
|
||||||
|
ctx.Writef("%s\n", str)
|
||||||
|
ctx.Next() // or ignroe that and use app.SetRegisterRules.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func onDone(ctx iris.Context) {
|
||||||
|
ctx.Writef("Called done: %s", ctx.Params().Get("name"))
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12/httptest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSamePatternDifferentFuncUseGlobal(t *testing.T) {
|
||||||
|
app := newApp()
|
||||||
|
e := httptest.New(t, app)
|
||||||
|
|
||||||
|
expectedResultFmt := "Called first middleware\nCalled second middleware\n%s\nCalled done: %s"
|
||||||
|
tests := map[string]string{
|
||||||
|
"/one-num": "first route",
|
||||||
|
"/two-num": "second route",
|
||||||
|
"/three-num": "third route",
|
||||||
|
}
|
||||||
|
|
||||||
|
for path, mainBody := range tests {
|
||||||
|
result := fmt.Sprintf(expectedResultFmt, mainBody, path[1:])
|
||||||
|
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(result)
|
||||||
|
}
|
||||||
|
}
|
|
@ -477,13 +477,14 @@ func (api *APIBuilder) createRoutes(errorCode int, methods []string, relativePat
|
||||||
// but dev may change the rules for that child Party, so we have to make clones of them here.
|
// but dev may change the rules for that child Party, so we have to make clones of them here.
|
||||||
|
|
||||||
var (
|
var (
|
||||||
beginHandlers context.Handlers
|
// global middleware to error handlers as well.
|
||||||
doneHandlers context.Handlers
|
beginHandlers = api.beginGlobalHandlers
|
||||||
|
doneHandlers = api.doneGlobalHandlers
|
||||||
)
|
)
|
||||||
|
|
||||||
if errorCode == 0 {
|
if errorCode == 0 {
|
||||||
beginHandlers = context.JoinHandlers(api.middleware, beginHandlers)
|
beginHandlers = context.JoinHandlers(beginHandlers, api.middleware)
|
||||||
doneHandlers = context.JoinHandlers(api.doneHandlers, doneHandlers)
|
doneHandlers = context.JoinHandlers(doneHandlers, api.doneHandlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainHandlers := context.Handlers(handlers)
|
mainHandlers := context.Handlers(handlers)
|
||||||
|
@ -532,8 +533,8 @@ func (api *APIBuilder) createRoutes(errorCode int, methods []string, relativePat
|
||||||
route.SourceLineNumber = mainHandlerFileNumber
|
route.SourceLineNumber = mainHandlerFileNumber
|
||||||
|
|
||||||
// Add UseGlobal & DoneGlobal Handlers
|
// Add UseGlobal & DoneGlobal Handlers
|
||||||
route.Use(api.beginGlobalHandlers...)
|
// route.Use(api.beginGlobalHandlers...)
|
||||||
route.Done(api.doneGlobalHandlers...)
|
// route.Done(api.doneGlobalHandlers...)
|
||||||
|
|
||||||
routes[i] = route
|
routes[i] = route
|
||||||
}
|
}
|
||||||
|
@ -771,7 +772,11 @@ func (api *APIBuilder) Use(handlers ...context.Handler) {
|
||||||
// It's always a good practise to call it right before the `Application#Run` function.
|
// It's always a good practise to call it right before the `Application#Run` function.
|
||||||
func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
|
func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
|
||||||
for _, r := range api.routes.routes {
|
for _, r := range api.routes.routes {
|
||||||
r.Use(handlers...) // prepend the handlers to the existing routes
|
// r.beginHandlers = append(handlers, r.beginHandlers...)
|
||||||
|
// ^ this is correct but we act global begin handlers as one chain, so
|
||||||
|
// if called last more than one time, after all routes registered, we must somehow
|
||||||
|
// register them by order, so:
|
||||||
|
r.Use(handlers...)
|
||||||
}
|
}
|
||||||
// set as begin handlers for the next routes as well.
|
// set as begin handlers for the next routes as well.
|
||||||
api.beginGlobalHandlers = append(api.beginGlobalHandlers, handlers...)
|
api.beginGlobalHandlers = append(api.beginGlobalHandlers, handlers...)
|
||||||
|
|
|
@ -64,6 +64,8 @@ var (
|
||||||
firstUseResponse + secondUseResponse + mainResponse + firstDoneResponse + secondDoneResponse
|
firstUseResponse + secondUseResponse + mainResponse + firstDoneResponse + secondDoneResponse
|
||||||
|
|
||||||
testResponse = func(t *testing.T, app *iris.Application, path string) {
|
testResponse = func(t *testing.T, app *iris.Application, path string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
e := httptest.New(t, app)
|
e := httptest.New(t, app)
|
||||||
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(finalResponse)
|
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(finalResponse)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user