summaryrefslogtreecommitdiff
path: root/service/gzip/service.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/gzip/service.go')
-rw-r--r--service/gzip/service.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/service/gzip/service.go b/service/gzip/service.go
new file mode 100644
index 00000000..86069c2f
--- /dev/null
+++ b/service/gzip/service.go
@@ -0,0 +1,32 @@
+package gzip
+
+import (
+ "github.com/NYTimes/gziphandler"
+ rrhttp "github.com/spiral/roadrunner/service/http"
+ "net/http"
+)
+
+// ID contains default service name.
+const ID = "gzip"
+
+type Service struct {
+ cfg *Config
+}
+
+func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) {
+ s.cfg = cfg
+
+ if s.cfg.Enable == false {
+ return false, nil
+ }
+
+ 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)
+ }
+}