Skip to content

Commit

Permalink
Fix Go 1.19 compatibility, update h3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
longsleep committed Sep 22, 2022
1 parent e80140f commit 309bbe3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 44 deletions.
7 changes: 6 additions & 1 deletion caddyhttp/httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
if s.Server.TLSConfig != nil {
// enable QUIC if desired (requires HTTP/2)
if HTTP2 && QUIC {
s.quicServer = &http3.Server{Server: s.Server}
s.quicServer = &http3.Server{
Addr: s.Server.Addr,
TLSConfig: s.Server.TLSConfig,
Handler: s.Server.Handler,
MaxHeaderBytes: s.Server.MaxHeaderBytes,
}
s.Server.Handler = s.wrapWithSvcHeaders(s.Server.Handler)
}

Expand Down
31 changes: 15 additions & 16 deletions caddyhttp/proxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int, t
rp.Transport = &http3.RoundTripper{
QuicConfig: &quic.Config{
HandshakeIdleTimeout: defaultCryptoHandshakeTimeout,
KeepAlive: true,
KeepAlivePeriod: 10 * time.Second,
},
}
} else if keepalive != http.DefaultMaxIdleConnsPerHost || strings.HasPrefix(target.Scheme, "srv") {
Expand Down Expand Up @@ -340,23 +340,22 @@ func (rp *ReverseProxy) UseOwnCACertificates(CaCertPool *x509.CertPool) {
// UseClientCertificates is used to facilitate HTTPS proxying
// with locally provided certificate.
func (rp *ReverseProxy) UseClientCertificates(keyPair *tls.Certificate) {
if transport, ok := rp.Transport.(*http.Transport); ok {
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.Certificates = []tls.Certificate{ *keyPair }
// No http2.ConfigureTransport() here.
// For now this is only added in places where
// an http.Transport is actually created.
} else if transport, ok := rp.Transport.(*http3.RoundTripper); ok {
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.Certificates = []tls.Certificate{ *keyPair }
}
if transport, ok := rp.Transport.(*http.Transport); ok {
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.Certificates = []tls.Certificate{*keyPair}
// No http2.ConfigureTransport() here.
// For now this is only added in places where
// an http.Transport is actually created.
} else if transport, ok := rp.Transport.(*http3.RoundTripper); ok {
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.Certificates = []tls.Certificate{*keyPair}
}
}


// ServeHTTP serves the proxied request to the upstream by performing a roundtrip.
// It is designed to handle websocket connection upgrades as well.
func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, respUpdateFn respUpdateFn) error {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ require (
github.com/naoina/toml v0.1.1
github.com/peterbourgon/unixtransport v0.0.1
github.com/russross/blackfriday v1.5.2
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
gopkg.in/mcuadros/go-syslog.v2 v2.2.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v2 v2.4.0
)

replace github.com/lucas-clemente/quic-go => github.com/lucas-clemente/quic-go v0.21.1
replace github.com/lucas-clemente/quic-go => github.com/lucas-clemente/quic-go v0.29.0
Loading

0 comments on commit 309bbe3

Please sign in to comment.