Nothing crazy, yet. Add an iris.StaticEmbeddedHandler shortcut of router.StaticEmbeddedHandler and extend the configuration's tests

Former-commit-id: 7a105c12ffe08f071bff2c212f96d648ed58c542
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-10-22 01:12:12 +03:00
parent 7372cfe38d
commit f95986d0c0
3 changed files with 78 additions and 4 deletions

View File

@ -421,7 +421,6 @@ Join the welcoming community of fellow _iris_ developers in [rocket.chat](https:
- :star: and watch the public [repository](https://github.com/kataras/iris/stargazers), will keep you up to date
- :earth_americas: publish [an article](https://medium.com/search?q=iris) or share a [tweet](https://twitter.com/hashtag/golang) about your personal experience with iris.
The most useful community repository for _iris_ developers is the
[iris-contrib/middleware](https://github.com/iris-contrib/middleware) which contains some HTTP handlers that can help you finish a lot of your tasks even easier. Feel free to push your own middleware there!

View File

@ -110,9 +110,16 @@ EnablePathEscape: false
FireMethodNotAllowed: true
EnableOptimizations: true
DisableBodyConsumptionOnUnmarshal: true
TimeFormat: Mon, 01 Jan 2006 15:04:05 GMT
Charset: UTF-8
TimeFormat: "Mon, 01 Jan 2006 15:04:05 GMT"
Charset: "UTF-8"
RemoteAddrHeaders:
X-Real-Ip: true
X-Forwarded-For: true
CF-Connecting-IP: true
Other:
MyServerName: "Iris: https://github.com/kataras/iris"
`
yamlFile.WriteString(yamlConfigurationContents)
filename := yamlFile.Name()
@ -151,6 +158,35 @@ Charset: UTF-8
if expected := "UTF-8"; c.Charset != expected {
t.Fatalf("error on TestConfigurationYAML: Expected Charset %s but got %s", expected, c.Charset)
}
if len(c.RemoteAddrHeaders) == 0 {
t.Fatalf("error on TestConfigurationYAML: Expected RemoteAddrHeaders to be filled")
}
expectedRemoteAddrHeaders := map[string]bool{
"X-Real-Ip": true,
"X-Forwarded-For": true,
"CF-Connecting-IP": true,
}
if expected, got := len(c.RemoteAddrHeaders), len(expectedRemoteAddrHeaders); expected != got {
t.Fatalf("error on TestConfigurationYAML: Expected RemoteAddrHeaders' len(%d) and got(%d), len is not the same", expected, got)
}
for k, v := range c.RemoteAddrHeaders {
if expected, got := expectedRemoteAddrHeaders[k], v; expected != got {
t.Fatalf("error on TestConfigurationYAML: Expected RemoteAddrHeaders[%s] = %t but got %t", k, expected, got)
}
}
if len(c.Other) == 0 {
t.Fatalf("error on TestConfigurationYAML: Expected Other to be filled")
}
if expected, got := "Iris: https://github.com/kataras/iris", c.Other["MyServerName"]; expected != got {
t.Fatalf("error on TestConfigurationYAML: Expected Other['MyServerName'] %s but got %s", expected, got)
}
}
func TestConfigurationTOML(t *testing.T) {
@ -175,9 +211,14 @@ DisableBodyConsumptionOnUnmarshal = true
TimeFormat = "Mon, 01 Jan 2006 15:04:05 GMT"
Charset = "UTF-8"
[RemoteAddrHeaders]
X-Real-Ip = true
X-Forwarded-For = true
CF-Connecting-IP = true
[Other]
# Indentation (tabs and/or spaces) is allowed but not required
MyServerName = "Iris"
MyServerName = "Iris: https://github.com/kataras/iris"
`
tomlFile.WriteString(tomlConfigurationContents)
@ -217,4 +258,32 @@ Charset = "UTF-8"
if expected := "UTF-8"; c.Charset != expected {
t.Fatalf("error on TestConfigurationTOML: Expected Charset %s but got %s", expected, c.Charset)
}
if len(c.RemoteAddrHeaders) == 0 {
t.Fatalf("error on TestConfigurationTOML: Expected RemoteAddrHeaders to be filled")
}
expectedRemoteAddrHeaders := map[string]bool{
"X-Real-Ip": true,
"X-Forwarded-For": true,
"CF-Connecting-IP": true,
}
if expected, got := len(c.RemoteAddrHeaders), len(expectedRemoteAddrHeaders); expected != got {
t.Fatalf("error on TestConfigurationTOML: Expected RemoteAddrHeaders' len(%d) and got(%d), len is not the same", expected, got)
}
for k, v := range c.RemoteAddrHeaders {
if expected, got := expectedRemoteAddrHeaders[k], v; expected != got {
t.Fatalf("error on TestConfigurationTOML: Expected RemoteAddrHeaders[%s] = %t but got %t", k, expected, got)
}
}
if len(c.Other) == 0 {
t.Fatalf("error on TestConfigurationTOML: Expected Other to be filled")
}
if expected, got := "Iris: https://github.com/kataras/iris", c.Other["MyServerName"]; expected != got {
t.Fatalf("error on TestConfigurationTOML: Expected Other['MyServerName'] %s but got %s", expected, got)
}
}

View File

@ -303,6 +303,12 @@ var (
//
// A shortcut for the `context#LimitRequestBodySize`.
LimitRequestBodySize = context.LimitRequestBodySize
// StaticEmbeddedHandler returns a Handler which can serve
// embedded into executable files.
//
//
// Examples: https://github.com/kataras/iris/tree/master/_examples/file-server
StaticEmbeddedHandler = router.StaticEmbeddedHandler
// Gzip is a middleware which enables writing
// using gzip compression, if client supports.
//