summaryrefslogtreecommitdiff
path: root/service/gzip
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-03-14 01:29:59 +0300
committerValery Piashchynski <[email protected]>2020-03-14 01:29:59 +0300
commit5e4c32f90db8ae6de541598304907974762f1673 (patch)
tree30b7197025d7830dd8575b850a3685d11d27fbfc /service/gzip
parent4ae5a7e7213798892d511a7a53ecd148e22ca7f6 (diff)
Fix potencial issue in gzip with cfg initialization
Add test for bug 275
Diffstat (limited to 'service/gzip')
-rw-r--r--service/gzip/service.go9
-rw-r--r--service/gzip/service_test.go14
2 files changed, 13 insertions, 10 deletions
diff --git a/service/gzip/service.go b/service/gzip/service.go
index 5ae3ffd5..231ba4d9 100644
--- a/service/gzip/service.go
+++ b/service/gzip/service.go
@@ -9,21 +9,20 @@ import (
// ID contains default service name.
const ID = "gzip"
-var httpNotInitialized = errors.New("http service should be defined properly in config")
+var httpNotInitialized = errors.New("http service should be defined properly in config to use gzip")
type Service struct {
cfg *Config
}
func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) {
- if r == nil {
- return false, httpNotInitialized
- }
s.cfg = cfg
-
if !s.cfg.Enable {
return false, nil
}
+ if r == nil {
+ return false, httpNotInitialized
+ }
r.AddMiddleware(s.middleware)
diff --git a/service/gzip/service_test.go b/service/gzip/service_test.go
index ba14b862..9a62a08b 100644
--- a/service/gzip/service_test.go
+++ b/service/gzip/service_test.go
@@ -13,7 +13,6 @@ import (
type testCfg struct {
gzip string
httpCfg string
- //static string
target string
}
@@ -31,15 +30,20 @@ func (cfg *testCfg) Unmarshal(out interface{}) error {
return json.Unmarshal([]byte(cfg.target), out)
}
-
func Test_Disabled(t *testing.T) {
logger, _ := test.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)
c := service.NewContainer(logger)
- c.Register(ID, &Service{})
+ c.Register(ID, &Service{cfg: &Config{Enable: true}})
assert.NoError(t, c.Init(&testCfg{
+ httpCfg: `{
+ "address": ":6029",
+ "workers":{
+ "command": "php ../../tests/http/client.php echo pipes",
+ }
+ }`,
gzip: `{"enable":false}`,
}))
@@ -57,8 +61,8 @@ func Test_Bug275(t *testing.T) {
c.Register(ID, &Service{})
assert.Error(t, c.Init(&testCfg{
- httpCfg:"",
- gzip: `{"enable":false}`,
+ httpCfg: "",
+ gzip: `{"enable":true}`,
}))
s, st := c.Get(ID)