feat: add rest.WithCustomCors to let caller customize the response (#1274)

This commit is contained in:
Kevin Wan
2021-11-25 23:03:37 +08:00
committed by GitHub
parent 86f9f63b46
commit 0395ba1816
4 changed files with 72 additions and 6 deletions

View File

@@ -310,3 +310,20 @@ Port: 54321
opt := WithCors("local")
opt(srv)
}
func TestWithCustomCors(t *testing.T) {
const configYaml = `
Name: foo
Port: 54321
`
var cnf RestConf
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
rt := router.NewRouter()
srv, err := NewServer(cnf, WithRouter(rt))
assert.Nil(t, err)
opt := WithCustomCors(func(w http.ResponseWriter) {
w.Header().Set("foo", "bar")
}, "local")
opt(srv)
}