Skip to content

Commit

Permalink
Optimize Setup HTTP/2
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Dec 4, 2024
1 parent cd7dde8 commit c14c8f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module github.com/bddjr/hlfhr

go 1.21

require golang.org/x/net v0.31.0

require golang.org/x/text v0.20.0 // indirect
4 changes: 0 additions & 4 deletions go.sum

This file was deleted.

20 changes: 7 additions & 13 deletions src_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"reflect"
"sync/atomic"
"unsafe"

"golang.org/x/net/http2"
)

type Server struct {
Expand Down Expand Up @@ -49,20 +47,16 @@ func NewServer(s *http.Server) *Server {
// ServeTLS always returns a non-nil error. After [Server.Shutdown] or [Server.Close], the
// returned error is [http.ErrServerClosed].
func (s *Server) ServeTLS(l net.Listener, certFile string, keyFile string) error {
// Setup HTTP/2 before srv.Serve, to initialize srv.TLSConfig
// before we clone it and create the TLS Listener.
err := http2.ConfigureServer(s.Server, nil)
if err != nil {
return err
// Setup HTTP/2
if s.TLSConfig == nil {
s.TLSConfig = &tls.Config{}
}
if len(s.TLSConfig.NextProtos) == 0 {
s.TLSConfig.NextProtos = []string{"h2", "http/1.1"}
}

// clone tls config
var config *tls.Config
if s.TLSConfig != nil {
config = s.TLSConfig.Clone()
} else {
config = &tls.Config{}
}
config := s.TLSConfig.Clone()

configHasCert := len(config.Certificates) > 0 || config.GetCertificate != nil || config.GetConfigForClient != nil
if !configHasCert || certFile != "" || keyFile != "" {
Expand Down

0 comments on commit c14c8f2

Please sign in to comment.