From fece9287e2f6a48a5203d5bb236afa0f19498343 Mon Sep 17 00:00:00 2001 From: Jeroen van Veen Date: Thu, 24 Dec 2020 14:44:16 +0100 Subject: [PATCH] Make https optional. --- galene.go | 2 ++ webserver/webserver.go | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/galene.go b/galene.go index ea72150..9ce9a57 100644 --- a/galene.go +++ b/galene.go @@ -24,6 +24,8 @@ func main() { "web server root `directory`") flag.StringVar(&webserver.Redirect, "redirect", "", "redirect to canonical `host`") + flag.BoolVar(&webserver.Insecure, "insecure", false, + "act as an HTTP server rather than HTTPS") flag.StringVar(&dataDir, "data", "./data/", "data `directory`") flag.StringVar(&group.Directory, "groups", "./groups/", diff --git a/webserver/webserver.go b/webserver/webserver.go index c98ddfb..8ab8ad7 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -33,6 +33,8 @@ var StaticRoot string var Redirect string +var Insecure bool + func Serve(address string, dataDir string) error { http.Handle("/", &fileHandler{http.Dir(StaticRoot)}) http.HandleFunc("/group/", groupHandler) @@ -68,10 +70,17 @@ func Serve(address string, dataDir string) error { server.Store(s) - err := s.ListenAndServeTLS( - filepath.Join(dataDir, "cert.pem"), - filepath.Join(dataDir, "key.pem"), - ) + var err error + + if !Insecure { + err = s.ListenAndServeTLS( + filepath.Join(dataDir, "cert.pem"), + filepath.Join(dataDir, "key.pem"), + ) + } else { + err = s.ListenAndServe() + } + if err == http.ErrServerClosed { return nil }