|
@@ -19,7 +19,6 @@ import (
|
|
|
"log"
|
|
"log"
|
|
|
"net"
|
|
"net"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
- "os/exec"
|
|
|
|
|
"path"
|
|
"path"
|
|
|
"regexp"
|
|
"regexp"
|
|
|
"runtime"
|
|
"runtime"
|
|
@@ -34,10 +33,13 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
- openFirefox = flag.Bool("openff", false, "Open Firefox")
|
|
|
|
|
- addr = flag.String("addr", "localhost:4430", "TLS address to listen on")
|
|
|
|
|
- httpAddr = flag.String("httpaddr", "", "If non-empty, address to listen for regular HTTP on")
|
|
|
|
|
- prod = flag.Bool("prod", false, "Whether to configure itself to be the production http2.golang.org server.")
|
|
|
|
|
|
|
+ prod = flag.Bool("prod", false, "Whether to configure itself to be the production http2.golang.org server.")
|
|
|
|
|
+
|
|
|
|
|
+ httpsAddr = flag.String("https_addr", "localhost:4430", "TLS address to listen on ('host:port' or ':port'). Required.")
|
|
|
|
|
+ httpAddr = flag.String("http_addr", "", "Plain HTTP address to listen on ('host:port', or ':port'). Empty means no HTTP.")
|
|
|
|
|
+
|
|
|
|
|
+ hostHTTP = flag.String("http_host", "", "Optional host or host:port to use for http:// links to this service. By default, this is implied from -http_addr.")
|
|
|
|
|
+ hostHTTPS = flag.String("https_host", "", "Optional host or host:port to use for http:// links to this service. By default, this is implied from -https_addr.")
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func homeOldHTTP(w http.ResponseWriter, r *http.Request) {
|
|
func homeOldHTTP(w http.ResponseWriter, r *http.Request) {
|
|
@@ -197,7 +199,7 @@ func registerHandlers() {
|
|
|
tiles.ServeHTTP(w, r)
|
|
tiles.ServeHTTP(w, r)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- http.Redirect(w, r, "https://http2.golang.org/", http.StatusFound)
|
|
|
|
|
|
|
+ http.Redirect(w, r, "https://"+httpsHost()+"/", http.StatusFound)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if r.ProtoMajor == 1 {
|
|
if r.ProtoMajor == 1 {
|
|
@@ -318,10 +320,10 @@ function showtimes() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func httpsHost() string {
|
|
func httpsHost() string {
|
|
|
- if *prod {
|
|
|
|
|
- return "http2.golang.org"
|
|
|
|
|
|
|
+ if *hostHTTPS != "" {
|
|
|
|
|
+ return *hostHTTPS
|
|
|
}
|
|
}
|
|
|
- if v := *addr; strings.HasPrefix(v, ":") {
|
|
|
|
|
|
|
+ if v := *httpsAddr; strings.HasPrefix(v, ":") {
|
|
|
return "localhost" + v
|
|
return "localhost" + v
|
|
|
} else {
|
|
} else {
|
|
|
return v
|
|
return v
|
|
@@ -329,8 +331,8 @@ func httpsHost() string {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func httpHost() string {
|
|
func httpHost() string {
|
|
|
- if *prod {
|
|
|
|
|
- return "http2.golang.org"
|
|
|
|
|
|
|
+ if *hostHTTP != "" {
|
|
|
|
|
+ return *hostHTTP
|
|
|
}
|
|
}
|
|
|
if v := *httpAddr; strings.HasPrefix(v, ":") {
|
|
if v := *httpAddr; strings.HasPrefix(v, ":") {
|
|
|
return "localhost" + v
|
|
return "localhost" + v
|
|
@@ -406,29 +408,29 @@ func main() {
|
|
|
var srv http.Server
|
|
var srv http.Server
|
|
|
flag.BoolVar(&http2.VerboseLogs, "verbose", false, "Verbose HTTP/2 debugging.")
|
|
flag.BoolVar(&http2.VerboseLogs, "verbose", false, "Verbose HTTP/2 debugging.")
|
|
|
flag.Parse()
|
|
flag.Parse()
|
|
|
- srv.Addr = *addr
|
|
|
|
|
|
|
+ srv.Addr = *httpsAddr
|
|
|
|
|
|
|
|
registerHandlers()
|
|
registerHandlers()
|
|
|
|
|
|
|
|
if *prod {
|
|
if *prod {
|
|
|
- *httpAddr = "http2.golang.org"
|
|
|
|
|
|
|
+ *hostHTTP = "http2.golang.org"
|
|
|
|
|
+ *hostHTTPS = "http2.golang.org"
|
|
|
log.Fatal(serveProd())
|
|
log.Fatal(serveProd())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- url := "https://" + *addr + "/"
|
|
|
|
|
|
|
+ url := "https://" + httpsHost() + "/"
|
|
|
log.Printf("Listening on " + url)
|
|
log.Printf("Listening on " + url)
|
|
|
http2.ConfigureServer(&srv, &http2.Server{})
|
|
http2.ConfigureServer(&srv, &http2.Server{})
|
|
|
|
|
|
|
|
if *httpAddr != "" {
|
|
if *httpAddr != "" {
|
|
|
- go func() { log.Fatal(http.ListenAndServe(*httpAddr, nil)) }()
|
|
|
|
|
|
|
+ go func() {
|
|
|
|
|
+ log.Printf("Listening on http://" + httpHost() + "/ (for unencrypted HTTP/1)")
|
|
|
|
|
+ log.Fatal(http.ListenAndServe(*httpAddr, nil))
|
|
|
|
|
+ }()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
|
log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
|
|
log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
|
|
|
}()
|
|
}()
|
|
|
- if *openFirefox && runtime.GOOS == "darwin" {
|
|
|
|
|
- time.Sleep(250 * time.Millisecond)
|
|
|
|
|
- exec.Command("open", "-b", "org.mozilla.nightly", "https://localhost:4430/").Run()
|
|
|
|
|
- }
|
|
|
|
|
select {}
|
|
select {}
|
|
|
}
|
|
}
|