|
|
@ -7,15 +7,19 @@ import (
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httputil"
|
|
|
|
"net/http/httputil"
|
|
|
|
|
|
|
|
//_ "net/http/pprof"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/fangdingjun/gnutls"
|
|
|
|
"crypto/tls"
|
|
|
|
|
|
|
|
//"github.com/fangdingjun/gnutls"
|
|
|
|
|
|
|
|
|
|
|
|
auth "github.com/fangdingjun/go-http-auth"
|
|
|
|
auth "github.com/fangdingjun/go-http-auth"
|
|
|
|
"github.com/fangdingjun/gofast"
|
|
|
|
"github.com/fangdingjun/gofast"
|
|
|
|
|
|
|
|
"github.com/fangdingjun/nghttp2-go"
|
|
|
|
loghandler "github.com/gorilla/handlers"
|
|
|
|
loghandler "github.com/gorilla/handlers"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -48,7 +52,7 @@ func initRouters(cfg conf) {
|
|
|
|
for _, l := range cfg {
|
|
|
|
for _, l := range cfg {
|
|
|
|
router := mux.NewRouter()
|
|
|
|
router := mux.NewRouter()
|
|
|
|
domains := []string{}
|
|
|
|
domains := []string{}
|
|
|
|
certs := []*gnutls.Certificate{}
|
|
|
|
certs := []tls.Certificate{}
|
|
|
|
|
|
|
|
|
|
|
|
// initial virtual host
|
|
|
|
// initial virtual host
|
|
|
|
for _, h := range l.Vhost {
|
|
|
|
for _, h := range l.Vhost {
|
|
|
@ -58,7 +62,7 @@ func initRouters(cfg conf) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
domains = append(domains, h2)
|
|
|
|
domains = append(domains, h2)
|
|
|
|
if h.Cert != "" && h.Key != "" {
|
|
|
|
if h.Cert != "" && h.Key != "" {
|
|
|
|
if cert, err := gnutls.LoadX509KeyPair(h.Cert, h.Key); err == nil {
|
|
|
|
if cert, err := tls.LoadX509KeyPair(h.Cert, h.Key); err == nil {
|
|
|
|
certs = append(certs, cert)
|
|
|
|
certs = append(certs, cert)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
@ -101,7 +105,7 @@ func initRouters(cfg conf) {
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//router.PathPrefix("/debug/").Handler(http.DefaultServeMux)
|
|
|
|
router.PathPrefix("/").Handler(http.FileServer(http.Dir(l.Docroot)))
|
|
|
|
router.PathPrefix("/").Handler(http.FileServer(http.Dir(l.Docroot)))
|
|
|
|
|
|
|
|
|
|
|
|
go func(l server) {
|
|
|
|
go func(l server) {
|
|
|
@ -127,30 +131,24 @@ func initRouters(cfg conf) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(certs) > 0 {
|
|
|
|
if len(certs) > 0 {
|
|
|
|
tlsconfig := &gnutls.Config{
|
|
|
|
tlsconfig := &tls.Config{
|
|
|
|
Certificates: certs,
|
|
|
|
Certificates: certs,
|
|
|
|
NextProtos: []string{"h2", "http/1.1"},
|
|
|
|
NextProtos: []string{"h2", "http/1.1"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listener, err := gnutls.Listen("tcp", addr, tlsconfig)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler := loghandler.CombinedLoggingHandler(w, hdlr)
|
|
|
|
handler := loghandler.CombinedLoggingHandler(w, hdlr)
|
|
|
|
//handler := hdlr
|
|
|
|
//handler := hdlr
|
|
|
|
log.Printf("listen https on %s", addr)
|
|
|
|
log.Printf("listen https on %s", addr)
|
|
|
|
go func() {
|
|
|
|
srv := &http.Server{
|
|
|
|
defer listener.Close()
|
|
|
|
Addr: addr,
|
|
|
|
for {
|
|
|
|
Handler: handler,
|
|
|
|
conn, err := listener.Accept()
|
|
|
|
TLSConfig: tlsconfig,
|
|
|
|
if err != nil {
|
|
|
|
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){
|
|
|
|
log.Println(err)
|
|
|
|
"h2": nghttp2.HTTP2Handler,
|
|
|
|
break
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go handleHTTPClient(conn, handler)
|
|
|
|
if err := srv.ListenAndServeTLS("", ""); err != nil {
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.Printf("listen http on %s", addr)
|
|
|
|
log.Printf("listen http on %s", addr)
|
|
|
|
handler := loghandler.CombinedLoggingHandler(w, hdlr)
|
|
|
|
handler := loghandler.CombinedLoggingHandler(w, hdlr)
|
|
|
|