Tidy webserver
This commit is contained in:
parent
a264ce76ed
commit
7c7117d8d6
@ -1,4 +1,4 @@
|
||||
package apiary
|
||||
|
||||
var Version = "v0.1.0"
|
||||
var Version = "v0.1.1"
|
||||
var Build string
|
||||
|
@ -22,23 +22,23 @@ import (
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
)
|
||||
|
||||
const streamKeepAliveDuration = 30 * time.Second
|
||||
|
||||
type Server struct {
|
||||
http.Server
|
||||
httpRedirectServer http.Server
|
||||
|
||||
cfg config.FrontendConfig
|
||||
|
||||
honeypotServer *honeypot.HoneypotServer
|
||||
store store.LoginAttemptStore
|
||||
|
||||
ServerLogger *zap.SugaredLogger
|
||||
AccessLogger *zap.SugaredLogger
|
||||
|
||||
honeypotServer *honeypot.HoneypotServer
|
||||
|
||||
attemptListenersLock sync.RWMutex
|
||||
attemptListeners map[string]chan models.LoginAttempt
|
||||
|
||||
streamContext context.Context
|
||||
httpRedirectServer http.Server
|
||||
}
|
||||
|
||||
func NewServer(cfg config.FrontendConfig, hs *honeypot.HoneypotServer, store store.LoginAttemptStore) *Server {
|
||||
@ -155,7 +155,7 @@ func (s *Server) HandlerAttemptStream(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
flusher := w.(http.Flusher)
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
ticker := time.NewTicker(streamKeepAliveDuration)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
@ -170,6 +170,7 @@ func (s *Server) HandlerAttemptStream(w http.ResponseWriter, r *http.Request) {
|
||||
s.ServerLogger.Warnw("Error writing event", "error", err)
|
||||
}
|
||||
flusher.Flush()
|
||||
ticker.Reset(streamKeepAliveDuration)
|
||||
case <-s.streamContext.Done():
|
||||
return
|
||||
case <-r.Context().Done():
|
||||
|
Loading…
Reference in New Issue
Block a user