Allow registry clients to connect via http2
Http2 will be enabled by default and can be disabled with a configuration option. Signed-off-by: Adam Duke <adam.v.duke@gmail.com>
This commit is contained in:
@@ -116,7 +116,7 @@ func (registry *Registry) ListenAndServe() error {
|
||||
if config.HTTP.TLS.Certificate != "" || config.HTTP.TLS.LetsEncrypt.CacheFile != "" {
|
||||
tlsConf := &tls.Config{
|
||||
ClientAuth: tls.NoClientCert,
|
||||
NextProtos: []string{"http/1.1"},
|
||||
NextProtos: nextProtos(config),
|
||||
MinVersion: tls.VersionTLS10,
|
||||
PreferServerCipherSuites: true,
|
||||
CipherSuites: []uint16{
|
||||
@@ -343,3 +343,12 @@ func resolveConfiguration(args []string) (*configuration.Configuration, error) {
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func nextProtos(config *configuration.Configuration) []string {
|
||||
switch config.HTTP.HTTP2.Disabled {
|
||||
case true:
|
||||
return []string{"http/1.1"}
|
||||
default:
|
||||
return []string{"h2", "http/1.1"}
|
||||
}
|
||||
}
|
||||
|
30
registry/registry_test.go
Normal file
30
registry/registry_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution/configuration"
|
||||
)
|
||||
|
||||
// Tests to ensure nextProtos returns the correct protocols when:
|
||||
// * config.HTTP.HTTP2.Disabled is not explicitly set => [h2 http/1.1]
|
||||
// * config.HTTP.HTTP2.Disabled is explicitly set to false [h2 http/1.1]
|
||||
// * config.HTTP.HTTP2.Disabled is explicitly set to true [http/1.1]
|
||||
func TestNextProtos(t *testing.T) {
|
||||
config := &configuration.Configuration{}
|
||||
protos := nextProtos(config)
|
||||
if !reflect.DeepEqual(protos, []string{"h2", "http/1.1"}) {
|
||||
t.Fatalf("expected protos to equal [h2 http/1.1], got %s", protos)
|
||||
}
|
||||
config.HTTP.HTTP2.Disabled = false
|
||||
protos = nextProtos(config)
|
||||
if !reflect.DeepEqual(protos, []string{"h2", "http/1.1"}) {
|
||||
t.Fatalf("expected protos to equal [h2 http/1.1], got %s", protos)
|
||||
}
|
||||
config.HTTP.HTTP2.Disabled = true
|
||||
protos = nextProtos(config)
|
||||
if !reflect.DeepEqual(protos, []string{"http/1.1"}) {
|
||||
t.Fatalf("expected protos to equal [http/1.1], got %s", protos)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user