Skip to content

Commit

Permalink
added the support for auto-redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alash3al committed Feb 24, 2018
1 parent 82171b7 commit b270149
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 9 additions & 8 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b270149

Please sign in to comment.