This commit is contained in:
Makis Maropoulos 2016-06-19 10:32:20 +03:00
parent 15139e33b7
commit 39e1504ba3
3 changed files with 13 additions and 8 deletions

View File

@ -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)
}

16
http.go
View File

@ -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

View File

@ -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().