diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 484c24ddc9..b2022889b0 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -480,6 +480,54 @@ func TestHandler_DeleteRetentionPolicy_NotFound(t *testing.T) { } } +func TestHandler_GzipEnabled(t *testing.T) { + srvr := OpenServer(NewMessagingClient()) + s := NewHTTPServer(srvr) + defer s.Close() + + req, err := http.NewRequest("GET", s.URL+`/ping`, bytes.NewBuffer([]byte{})) + if err != nil { + panic(err) + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Accept-Encoding", "gzip") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + panic(err) + } + + if ce := resp.Header.Get("Content-Encoding"); ce != "gzip" { + t.Fatalf("unexpected Content-Encoding. expected %q, actual: %q", "gzip", ce) + } +} + +func TestHandler_GzipDisabled(t *testing.T) { + srvr := OpenServer(NewMessagingClient()) + s := NewHTTPServer(srvr) + defer s.Close() + + req, err := http.NewRequest("GET", s.URL+`/ping`, bytes.NewBuffer([]byte{})) + if err != nil { + panic(err) + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Accept-Encoding", "") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + panic(err) + } + + if ce := resp.Header.Get("Content-Encoding"); ce == "gzip" { + t.Fatalf("unexpected Content-Encoding. expected %q, actual: %q", "", ce) + } +} + func TestHandler_Ping(t *testing.T) { srvr := OpenServer(NewMessagingClient()) s := NewHTTPServer(srvr)