Skip to content

Commit

Permalink
Adding a gzip handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynom committed Jul 3, 2018
1 parent 72b9500 commit 71d79bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func main() {
server.WithLogger(logger),
server.WithCORS(config.CORS.AllowedOrigins),
server.WithInputLimitValidator(config.Client.InputLengthMax),
server.WithGzipHandler(),
)

err = s.ListenOnAndServe(config.Server.ListenOn)
Expand Down
8 changes: 8 additions & 0 deletions server/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"fmt"

"github.com/NYTimes/gziphandler"
"github.com/rs/cors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -56,3 +57,10 @@ func WithInputLimitValidator(inputMax int) Option {
})
}
}

// WithGzipHandler adds a gzip handler to the server's handlers
func WithGzipHandler() Option {
return func(server *TySugServer) {
server.handlers = append(server.handlers, gziphandler.GzipHandler)
}
}

0 comments on commit 71d79bb

Please sign in to comment.