Added option to toggle gzip as it causes air browser refresh to break
This commit is contained in:
@@ -17,6 +17,7 @@ type Config struct {
|
|||||||
Port string // Port to listen on
|
Port string // Port to listen on
|
||||||
TrustedHost string // Domain/Hostname to accept as trusted
|
TrustedHost string // Domain/Hostname to accept as trusted
|
||||||
SSL bool // Flag for SSL Mode
|
SSL bool // Flag for SSL Mode
|
||||||
|
GZIP bool // Flag for GZIP compression on requests
|
||||||
ReadHeaderTimeout time.Duration // Timeout for reading request headers in seconds
|
ReadHeaderTimeout time.Duration // Timeout for reading request headers in seconds
|
||||||
WriteTimeout time.Duration // Timeout for writing requests in seconds
|
WriteTimeout time.Duration // Timeout for writing requests in seconds
|
||||||
IdleTimeout time.Duration // Timeout for idle connections in seconds
|
IdleTimeout time.Duration // Timeout for idle connections in seconds
|
||||||
@@ -84,6 +85,7 @@ func GetConfig(args map[string]string) (*Config, error) {
|
|||||||
Port: port,
|
Port: port,
|
||||||
TrustedHost: GetEnvDefault("TRUSTED_HOST", "127.0.0.1"),
|
TrustedHost: GetEnvDefault("TRUSTED_HOST", "127.0.0.1"),
|
||||||
SSL: GetEnvBool("SSL_MODE", false),
|
SSL: GetEnvBool("SSL_MODE", false),
|
||||||
|
GZIP: GetEnvBool("GZIP", false),
|
||||||
ReadHeaderTimeout: GetEnvDur("READ_HEADER_TIMEOUT", 2),
|
ReadHeaderTimeout: GetEnvDur("READ_HEADER_TIMEOUT", 2),
|
||||||
WriteTimeout: GetEnvDur("WRITE_TIMEOUT", 10),
|
WriteTimeout: GetEnvDur("WRITE_TIMEOUT", 10),
|
||||||
IdleTimeout: GetEnvDur("IDLE_TIMEOUT", 120),
|
IdleTimeout: GetEnvDur("IDLE_TIMEOUT", 120),
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Gzip(next http.Handler) http.Handler {
|
func Gzip(next http.Handler, useGzip bool) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") ||
|
||||||
|
!useGzip {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func NewServer(
|
|||||||
handler = middleware.Favicon(handler)
|
handler = middleware.Favicon(handler)
|
||||||
|
|
||||||
// Gzip
|
// Gzip
|
||||||
handler = middleware.Gzip(handler)
|
handler = middleware.Gzip(handler, config.GZIP)
|
||||||
|
|
||||||
// Start the timer for the request chain so logger can have accurate info
|
// Start the timer for the request chain so logger can have accurate info
|
||||||
handler = middleware.StartTimer(handler)
|
handler = middleware.StartTimer(handler)
|
||||||
|
|||||||
Reference in New Issue
Block a user