Commit 3d691bf4 authored by Kamil Trzciński's avatar Kamil Trzciński

Move most of configuration to appConfig

parent 3824fc8c
......@@ -44,7 +44,7 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo
defer w.Log(r)
// Add auto redirect
if https && !*serverHTTP {
if https && !a.RedirectHTTP {
u := *r.URL
u.Scheme = "https"
u.Host = r.Host
......@@ -89,7 +89,7 @@ func (a *theApp) Run() {
wg.Add(1)
go func() {
defer wg.Done()
err := listenAndServe(a.ListenHTTP, a.ServeHTTP, nil)
err := listenAndServe(a.ListenHTTP, a.ServeHTTP, a.HTTP2, nil)
if err != nil {
log.Fatal(err)
}
......@@ -101,7 +101,7 @@ func (a *theApp) Run() {
wg.Add(1)
go func() {
defer wg.Done()
err := listenAndServeTLS(a.ListenHTTPS, a.RootCertificate, a.RootKey, a.ServeHTTP, a.ServeTLS)
err := listenAndServeTLS(a.ListenHTTPS, a.RootCertificate, a.RootKey, a.ServeHTTP, a.ServeTLS, a.HTTP2)
if err != nil {
log.Fatal(err)
}
......@@ -113,7 +113,7 @@ func (a *theApp) Run() {
wg.Add(1)
go func() {
defer wg.Done()
err := listenAndServe(a.listenProxy, a.ServeProxy, nil)
err := listenAndServe(a.listenProxy, a.ServeProxy, a.HTTP2, nil)
if err != nil {
log.Fatal(err)
}
......
package main
type appConfig struct {
Domain string
RootDir string
Domain string
RootDir string
RootCertificate []byte
RootKey []byte
ListenHTTP uintptr
ListenHTTPS uintptr
listenProxy uintptr
ListenHTTP uintptr
ListenHTTPS uintptr
listenProxy uintptr
HTTP2 bool
ServeHTTP bool
HTTP2 bool
RedirectHTTP bool
}
......@@ -16,8 +16,6 @@ var VERSION = "dev"
var REVISION = "HEAD"
var pagesDomain = flag.String("pages-domain", "gitlab-example.com", "The domain to serve static pages")
var serverHTTP = flag.Bool("serve-http", true, "Serve the pages under HTTP")
var http2proto = flag.Bool("http2", true, "Enable HTTP2 support")
var pagesRoot = flag.String("pages-root", "shared/pages", "The directory where pages are stored")
func evalSymlinks(directory string) (result string) {
......@@ -57,6 +55,8 @@ func main() {
var listenProxy = flag.String("listen-proxy", "", "The address to listen for proxy requests")
var pagesRootCert = flag.String("root-cert", "", "The default path to file certificate to serve static pages")
var pagesRootKey = flag.String("root-key", "", "The default path to file certificate to serve static pages")
var redirectHTTP = flag.Bool("redirect-http", true, "Serve the pages under HTTP")
var useHTTP2 = flag.Bool("use-http2", true, "Enable HTTP2 support")
fmt.Printf("GitLab Pages Daemon %s (%s)", VERSION, REVISION)
fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages")
......@@ -66,6 +66,8 @@ func main() {
app.Domain = *pagesDomain
app.RootDir = evalSymlinks(*pagesRoot)
app.RedirectHTTP = *redirectHTTP
app.HTTP2 = *useHTTP2
if *pagesRootCert != "" {
app.RootCertificate = readFile(*pagesRootCert)
......
......@@ -26,11 +26,11 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
return tc, nil
}
func listenAndServe(fd uintptr, handler http.HandlerFunc, tlsConfig *tls.Config) error {
func listenAndServe(fd uintptr, handler http.HandlerFunc, useHTTP2 bool, tlsConfig *tls.Config) error {
// create server
server := &http.Server{Handler: handler, TLSConfig: tlsConfig}
if *http2proto {
if useHTTP2 {
err := http2.ConfigureServer(server, &http2.Server{})
if err != nil {
return err
......@@ -50,7 +50,7 @@ func listenAndServe(fd uintptr, handler http.HandlerFunc, tlsConfig *tls.Config)
}
}
func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc, tlsHandler tlsHandlerFunc) error {
func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc,tlsHandler tlsHandlerFunc, useHTTP2 bool) error {
certificate, err := tls.X509KeyPair(cert, key)
if err != nil {
return err
......@@ -64,5 +64,5 @@ func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc, t
tlsConfig.Certificates = []tls.Certificate{
certificate,
}
return listenAndServe(fd, handler, tlsConfig)
return listenAndServe(fd, handler, useHTTP2, tlsConfig)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment