diff options
author | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
commit | 0dc44d54cfcc9dd3fa09a41136f35a9a8d26b994 (patch) | |
tree | ffcb65010bebe9f5b5436192979e64b2402a6ec0 /service/gzip/service.go | |
parent | 08d6b6b7f773f83b286cd48c1a0fbec9a62fb42b (diff) |
Initial commit of RR 2.0v2.0.0-alpha1
Diffstat (limited to 'service/gzip/service.go')
-rw-r--r-- | service/gzip/service.go | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/service/gzip/service.go b/service/gzip/service.go deleted file mode 100644 index 231ba4d9..00000000 --- a/service/gzip/service.go +++ /dev/null @@ -1,36 +0,0 @@ -package gzip - -import ( - "errors" - "github.com/NYTimes/gziphandler" - rrhttp "github.com/spiral/roadrunner/service/http" - "net/http" -) - -// ID contains default service name. -const ID = "gzip" -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) { - s.cfg = cfg - if !s.cfg.Enable { - return false, nil - } - if r == nil { - return false, httpNotInitialized - } - - r.AddMiddleware(s.middleware) - - return true, nil -} - -func (s *Service) middleware(f http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - gziphandler.GzipHandler(f).ServeHTTP(w, r) - } -} |