use go http2 library

master
fangdingjun 6 years ago
parent 4aa5ef896e
commit f54e957d42

@ -7,8 +7,9 @@ import (
"net/http" "net/http"
"github.com/fangdingjun/go-log" "github.com/fangdingjun/go-log"
"github.com/fangdingjun/nghttp2-go" //"github.com/fangdingjun/nghttp2-go"
"github.com/miekg/dns" "github.com/miekg/dns"
"golang.org/x/net/http2"
) )
func (srv *server) handleHTTPSConn(c net.Conn) { func (srv *server) handleHTTPSConn(c net.Conn) {
@ -23,12 +24,11 @@ func (srv *server) handleHTTPSConn(c net.Conn) {
log.Errorln("http2 is needed") log.Errorln("http2 is needed")
return return
} }
h2conn, err := nghttp2.Server(tlsconn, srv) _srv := &http2.Server{}
if err != nil { _srv.ServeConn(c, &http2.ServeConnOpts{
log.Errorf("create http2 error: %s", err) BaseConfig: &http.Server{},
return Handler: srv,
} })
h2conn.Run()
} }
func (srv *server) handleHTTP2Req(w http.ResponseWriter, r *http.Request) { func (srv *server) handleHTTP2Req(w http.ResponseWriter, r *http.Request) {

@ -10,8 +10,9 @@ import (
"time" "time"
"github.com/fangdingjun/go-log" "github.com/fangdingjun/go-log"
nghttp2 "github.com/fangdingjun/nghttp2-go" //nghttp2 "github.com/fangdingjun/nghttp2-go"
"github.com/miekg/dns" "github.com/miekg/dns"
"golang.org/x/net/http2"
) )
var dnsClientTCP *dns.Client var dnsClientTCP *dns.Client
@ -108,13 +109,13 @@ func initDNSClient(c *conf) {
Net: "https", Net: "https",
Timeout: time.Duration(c.UpstreamTimeout) * time.Second, Timeout: time.Duration(c.UpstreamTimeout) * time.Second,
HTTPClient: &http.Client{ HTTPClient: &http.Client{
Transport: &nghttp2.Transport{ Transport: &http2.Transport{
DialTLS: func(network, addr string, cfg *tls.Config) (*tls.Conn, error) { DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
log.Debugln("dial to", network, addr) log.Debugln("dial to", network, addr)
conn, err := tls.DialWithDialer(dialer, network, addr, cfg) conn, err := tls.DialWithDialer(dialer, network, addr, cfg)
return conn, err return conn, err
}, },
TLSConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: c.UpstreamInsecure, InsecureSkipVerify: c.UpstreamInsecure,
NextProtos: []string{"h2"}, NextProtos: []string{"h2"},
}, },

Loading…
Cancel
Save