* move HTTP server code

This commit is contained in:
Simon Zolin
2020-02-19 15:24:55 +03:00
parent 0789e4b20d
commit 8e4bc29103
6 changed files with 234 additions and 159 deletions

View File

@@ -82,7 +82,7 @@ func handleTLSValidate(w http.ResponseWriter, r *http.Request) {
// check if port is available
// BUT: if we are already using this port, no need
alreadyRunning := false
if Context.httpsServer.server != nil {
if Context.web.httpsServer.server != nil {
alreadyRunning = true
}
if !alreadyRunning {
@@ -112,7 +112,7 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
// check if port is available
// BUT: if we are already using this port, no need
alreadyRunning := false
if Context.httpsServer.server != nil {
if Context.web.httpsServer.server != nil {
alreadyRunning = true
}
if !alreadyRunning {
@@ -147,12 +147,12 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
if restartHTTPS {
go func() {
time.Sleep(time.Second) // TODO: could not find a way to reliably know that data was fully sent to client by https server, so we wait a bit to let response through before closing the server
Context.httpsServer.cond.L.Lock()
Context.httpsServer.cond.Broadcast()
if Context.httpsServer.server != nil {
Context.httpsServer.server.Shutdown(context.TODO())
Context.web.httpsServer.cond.L.Lock()
Context.web.httpsServer.cond.Broadcast()
if Context.web.httpsServer.server != nil {
Context.web.httpsServer.server.Shutdown(context.TODO())
}
Context.httpsServer.cond.L.Unlock()
Context.web.httpsServer.cond.L.Unlock()
}()
}
}