Browse Source

added the support for auto-redirect

Mohamed Al Ashaal 6 years ago
parent
commit
b27014970c
2 changed files with 14 additions and 9 deletions
  1. 9 8
      flags.go
  2. 5 1
      server.go

+ 9 - 8
flags.go

@@ -9,14 +9,15 @@ import (
 import "github.com/mitchellh/go-homedir"
 
 var (
-	VERSION     = "httpsify/v3.1"
-	HOME_DIR, _ = homedir.Dir()
-	HTTP_ADDR   = flag.String("http", ":http", "the http address to listen on")
-	HTTPS_ADDR  = flag.String("https", ":https", "the https address to listen on")
-	STORAGE     = flag.String("storage", path.Join(HOME_DIR, ".httpsify/certs"), "the ssl certs storage directory")
-	HOSTS_FILE  = flag.String("hosts", path.Join(HOME_DIR, ".httpsify/hosts.json"), "the sites configurations filename")
-	HSTS        = flag.String("hsts", "max-age=86400; includeSubDomains", "the hsts header value, empty value means disable")
-	EXPOSE_INFO = flag.Bool("expose-info", true, "whether to expose the httpsify info header or not")
+	VERSION      = "httpsify/v3.1"
+	HOME_DIR, _  = homedir.Dir()
+	HTTP_ADDR    = flag.String("http", ":http", "the http address to listen on")
+	HTTPS_ADDR   = flag.String("https", ":https", "the https address to listen on")
+	AUTOREDIRECT = flag.Bool("redirect", false, "automatically redirect http traffic to https")
+	STORAGE      = flag.String("storage", path.Join(HOME_DIR, ".httpsify/certs"), "the ssl certs storage directory")
+	HOSTS_FILE   = flag.String("hosts", path.Join(HOME_DIR, ".httpsify/hosts.json"), "the sites configurations filename")
+	HSTS         = flag.String("hsts", "max-age=86400; includeSubDomains", "the hsts header value, empty value means disable")
+	EXPOSE_INFO  = flag.Bool("expose-info", true, "whether to expose the httpsify info header or not")
 )
 
 func InitFlags() {

+ 5 - 1
server.go

@@ -42,7 +42,11 @@ func InitServer() error {
 	log.SetOutput(ioutil.Discard)
 
 	go (func() {
-		errchan <- http.ListenAndServe(*HTTP_ADDR, m.HTTPHandler(nil))
+		handler := m.HTTPHandler(nil)
+		if *AUTOREDIRECT {
+			handler = m.HTTPHandler(ServeHTTP())
+		}
+		errchan <- http.ListenAndServe(*HTTP_ADDR, handler)
 	})()
 
 	go (func() {