diff --git a/context.go b/context.go index f521bfd1..e72b26ed 100644 --- a/context.go +++ b/context.go @@ -387,7 +387,10 @@ func (ctx *Context) SetContentType(s string) { } // SetHeader write to the response writer's header to a given key the given value(s) +// +// Note: If you want to send a multi-line string as header's value use: strings.TrimSpace first. func (ctx *Context) SetHeader(k string, v string) { + //v = strings.TrimSpace(v) ctx.RequestCtx.Response.Header.Set(k, v) } diff --git a/http.go b/http.go index 6165f3e3..281dca1e 100644 --- a/http.go +++ b/http.go @@ -240,8 +240,8 @@ type Server struct { *fasthttp.Server listener net.Listener Config *config.Server - started bool tls bool + mu sync.Mutex } // newServer returns a pointer to a Server object, and set it's options if any, nothing more @@ -259,7 +259,9 @@ func (s *Server) SetHandler(mux *serveMux) { // IsListening returns true if server is listening/started, otherwise false func (s *Server) IsListening() bool { - return s.started && s.listener != nil && s.listener.Addr().String() != "" + s.mu.Lock() + defer s.mu.Unlock() + return s.listener != nil && s.listener.Addr().String() != "" } // IsSecure returns true if server uses TLS, otherwise false @@ -311,7 +313,7 @@ func (s *Server) VirtualHostname() (hostname string) { } func (s *Server) listen() error { - if s.started { + if s.IsListening() { return errServerAlreadyStarted.Return() } listener, err := net.Listen("tcp4", s.Config.ListeningAddr) @@ -351,9 +353,9 @@ func (s *Server) listenUNIX() error { //Serve just serves a listener, it is a blocking action, plugin.PostListen is not fired here. func (s *Server) serve(l net.Listener) error { + s.mu.Lock() s.listener = l - s.started = true - + s.mu.Unlock() if s.Config.CertFile != "" && s.Config.KeyFile != "" { s.tls = true return s.Server.ServeTLS(s.listener, s.Config.CertFile, s.Config.KeyFile) @@ -392,10 +394,10 @@ func (s *Server) Open() error { // close closes the server func (s *Server) close() (err error) { - if !s.started || s.listener == nil { + if !s.IsListening() { return errServerIsClosed.Return() } - s.started = false + err = s.listener.Close() return diff --git a/logger/logger.go b/logger/logger.go index 75b4e7df..c8170efb 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -111,7 +111,7 @@ func (l *Logger) Fatalf(format string, a ...interface{}) { // Panic is equivalent to l.Dangerf("%#v",interface{}) followed by a call to panic(). func (l *Logger) Panic(a interface{}) { l.Dangerf("%s\n", a) - panic("") + panic(a) } // Panicf is equivalent to l.Dangerf() followed by a call to panic().