Repository navigation
add NewServerTLS - #2708
add NewServerTLS#2708davidhadas wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: davidhadas The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/cc @evankanderson |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
| // NewServerTLS is same as NewServer but allows configuring the server's TLSConfig | ||
| func NewServerTLS(addr string, h http.Handler, tlsConfig *tls.Config) *http.Server { | ||
| //nolint:gosec | ||
| h1s := &http.Server{ | ||
| Addr: addr, | ||
| Handler: h2c.NewHandler(h, &http2.Server{}), | ||
| TLSConfig: tlsConfig, | ||
| } | ||
|
|
||
| return h1s | ||
| } | ||
|
|
There was a problem hiding this comment.
Consider using the functional options pattern:
This would look like:
type ServerOption func(*http.Server)
func WithTLSConfig(tlsConfig *tls.Config) ServerOption {
return func(s *http.Server) {
s.TLSConfig = tlsConfig
}
}
func NewServer(addr string, h http.Handler, opts ...ServerOption) *http.Server {
h1s := ...
for _, opt := range opts {
opt(h1s)
}
return h1s
}Among other things, it will ensure that the NewServerTLS and other implementations also implement the slowloris attack mitigation on line 47.
Also, it will avoid creating many NewServerFoo implementations, at the cost of writing:
srv = NewServer(":8080", myHandler, WithTLSConfig(myTLS))
|
server := pkg.NewServer(...)
server.TLSConfig = ... |
That is a very good point :) |
Add another public function to pkg h2c that allows configuring the server's tls.Config
Fix #2699