overflow_gateway_webapp/server/server_handlers.go
crusader e92a8ead89 ing
2017-11-14 19:10:28 +09:00

52 lines
1.2 KiB
Go

package server
import (
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
"github.com/valyala/fasthttp"
)
func NewServerHandler() ServerHandler {
sh := &ServerHandlers{}
sh.ServerHandler = oogws.NewServerHandler()
return sh
}
type ServerHandlers struct {
oogws.ServerHandler
}
// Init invoked before the server is started
// If you override ths method, must call
func (sh *ServerHandlers) Init() error {
if err := sh.ServerHandler.Init(); nil != err {
return err
}
return nil
}
func (sh *ServerHandlers) OnStart() {
sh.ServerHandler.OnStart()
}
func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
if origin := string(ctx.Request.Header.Peek("Origin")); origin != "" {
ctx.Response.Header.Set("Access-Control-Allow-Origin", origin)
if string(ctx.Method()) == "OPTIONS" && string(ctx.Request.Header.Peek("Access-Control-Request-Method")) != "" {
ctx.Response.Header.Set("Access-Control-Allow-Headers", "Content-Type, Accept")
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE")
}
}
return true
}
func (sh *ServerHandlers) OnStop() {
sh.ServerHandler.OnStop()
}
func (sh *ServerHandlers) Validate() {
sh.ServerHandler.Validate()
}