summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Patsura <[email protected]>2019-06-14 16:45:52 +0300
committerDmitry Patsura <[email protected]>2019-06-14 16:46:11 +0300
commit15746d3706fb9ed1e4a8e7d925f033878744b6a1 (patch)
treef775f49826c327234a176d0c35fa95fbe4bc99db
parent928bff44e21997e4b5f1caefa0e8a627a235b01d (diff)
Feature(http): Ability to disable HTTP2
-rw-r--r--.rr.yaml1
-rw-r--r--service/http/config.go28
-rw-r--r--service/http/config_test.go55
-rw-r--r--service/http/service.go9
4 files changed, 81 insertions, 12 deletions
diff --git a/.rr.yaml b/.rr.yaml
index fa94bcff..198f777b 100644
--- a/.rr.yaml
+++ b/.rr.yaml
@@ -35,6 +35,7 @@ http:
# HTTP service provides HTTP2 transport
http2:
+ enabled: true
maxConcurrentStreams: 128
# max POST request size, including file uploads in MB.
diff --git a/service/http/config.go b/service/http/config.go
index caf94d98..b4575914 100644
--- a/service/http/config.go
+++ b/service/http/config.go
@@ -18,8 +18,6 @@ type Config struct {
// SSL defines https server options.
SSL SSLConfig
- HTTP2 *HTTP2Config
-
FCGI FCGIConfig
// MaxRequestSize specified max size for payload body in megabytes, set 0 to unlimited.
@@ -32,6 +30,9 @@ type Config struct {
// Uploads configures uploads configuration.
Uploads *UploadsConfig
+ // HTTP2 configuration
+ HTTP2 *HTTP2Config
+
// Workers configures rr server and worker pool.
Workers *roadrunner.ServerConfig
}
@@ -42,9 +43,17 @@ type FCGIConfig struct {
}
type HTTP2Config struct {
+ Enabled bool
MaxConcurrentStreams uint32
}
+func (cfg *HTTP2Config) InitDefaults() error {
+ cfg.Enabled = true
+ cfg.MaxConcurrentStreams = 128
+
+ return nil
+}
+
// SSLConfig defines https server configuration.
type SSLConfig struct {
// Port to listen as HTTPS server, defaults to 443.
@@ -79,6 +88,10 @@ func (c *Config) Hydrate(cfg service.Config) error {
c.Workers = &roadrunner.ServerConfig{}
}
+ if c.HTTP2 == nil {
+ c.HTTP2 = &HTTP2Config{}
+ }
+
if c.Uploads == nil {
c.Uploads = &UploadsConfig{}
}
@@ -87,12 +100,7 @@ func (c *Config) Hydrate(cfg service.Config) error {
c.SSL.Port = 443
}
- if c.HTTP2 == nil {
- c.HTTP2 = &HTTP2Config{
- MaxConcurrentStreams: 128,
- }
- }
-
+ c.HTTP2.InitDefaults()
c.Uploads.InitDefaults()
c.Workers.InitDefaults()
@@ -161,6 +169,10 @@ func (c *Config) Valid() error {
return errors.New("mailformed uploads config")
}
+ if c.HTTP2 == nil {
+ return errors.New("mailformed http2 config")
+ }
+
if c.Workers == nil {
return errors.New("mailformed workers config")
}
diff --git a/service/http/config_test.go b/service/http/config_test.go
index 54e5b27a..6bb314d8 100644
--- a/service/http/config_test.go
+++ b/service/http/config_test.go
@@ -33,6 +33,9 @@ func Test_Config_Valid(t *testing.T) {
cfg := &Config{
Address: ":8080",
MaxRequestSize: 1024,
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Uploads: &UploadsConfig{
Dir: os.TempDir(),
Forbid: []string{".go"},
@@ -59,6 +62,9 @@ func Test_Trusted_Subnets(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
TrustedSubnets: []string{"200.1.0.0/16"},
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
@@ -85,6 +91,9 @@ func Test_Trusted_Subnets_Err(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
TrustedSubnets: []string{"200.1.0.0"},
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
@@ -112,6 +121,9 @@ func Test_Config_Valid_SSL(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -141,6 +153,9 @@ func Test_Config_SSL_No_key(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -166,6 +181,9 @@ func Test_Config_SSL_No_Cert(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -184,6 +202,9 @@ func Test_Config_NoUploads(t *testing.T) {
cfg := &Config{
Address: ":8080",
MaxRequestSize: 1024,
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -198,10 +219,35 @@ func Test_Config_NoUploads(t *testing.T) {
assert.Error(t, cfg.Valid())
}
+func Test_Config_NoHTTP2(t *testing.T) {
+ cfg := &Config{
+ Address: ":8080",
+ MaxRequestSize: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{".go"},
+ },
+ Workers: &roadrunner.ServerConfig{
+ Command: "php tests/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 0,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ },
+ }
+
+ assert.Error(t, cfg.Valid())
+}
+
func Test_Config_NoWorkers(t *testing.T) {
cfg := &Config{
Address: ":8080",
MaxRequestSize: 1024,
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Uploads: &UploadsConfig{
Dir: os.TempDir(),
Forbid: []string{".go"},
@@ -219,6 +265,9 @@ func Test_Config_NoPool(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -241,6 +290,9 @@ func Test_Config_DeadPool(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
@@ -258,6 +310,9 @@ func Test_Config_InvalidAddress(t *testing.T) {
Dir: os.TempDir(),
Forbid: []string{".go"},
},
+ HTTP2: &HTTP2Config{
+ Enabled: true,
+ },
Workers: &roadrunner.ServerConfig{
Command: "php tests/client.php echo pipes",
Relay: "pipes",
diff --git a/service/http/service.go b/service/http/service.go
index 8e0d10ee..25b98a4c 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -209,10 +209,11 @@ func (s *Service) initSSL() *http.Server {
server := &http.Server{Addr: s.tlsAddr(s.cfg.Address, true), Handler: s}
s.throw(EventInitSSL, server)
- // Enable HTTP/2 support by default
- http2.ConfigureServer(server, &http2.Server{
- MaxConcurrentStreams: s.cfg.HTTP2.MaxConcurrentStreams,
- })
+ if s.cfg.HTTP2.Enabled {
+ http2.ConfigureServer(server, &http2.Server{
+ MaxConcurrentStreams: s.cfg.HTTP2.MaxConcurrentStreams,
+ })
+ }
return server
}