mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
add options feature on apps package and add a SetHost option to force host on multiple subdomains that should mean the same exact application, so any handler should run based on the same Host field
This commit is contained in:
38
apps/switch_options_test.go
Normal file
38
apps/switch_options_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package apps
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestSetHost(t *testing.T) {
|
||||
var (
|
||||
index = func(ctx iris.Context) {
|
||||
ctx.Header("Server", ctx.Application().String())
|
||||
ctx.WriteString(ctx.Host())
|
||||
}
|
||||
|
||||
forceHost = "www.mydomain.com"
|
||||
)
|
||||
|
||||
rootApp := iris.New().SetName("My Server")
|
||||
rootApp.Get("/", index)
|
||||
|
||||
switcher := Switch(Hosts{
|
||||
{"^(www.)?mydomain.com$", rootApp},
|
||||
}, SetHost(forceHost))
|
||||
|
||||
e := httptest.New(t, switcher)
|
||||
tests := []*httptest.Request{
|
||||
e.GET("/").WithURL("http://mydomain.com"),
|
||||
e.GET("/").WithURL("http://www.mydomain.com"),
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
ex := tt.Expect().Status(iris.StatusOK)
|
||||
ex.Header("Server").Equal(rootApp.String())
|
||||
ex.Body().Equal(forceHost)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user