Skip to content

Commit 60ecea5

Browse files
authored
feat(middleware): add text/markdown, text/csv, text/vtt to default compressible types (#1151)
1 parent 8b258c7 commit 60ecea5

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎middleware/compress.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ var defaultCompressibleContentTypes = []string{
1818
"text/css",
1919
"text/plain",
2020
"text/javascript",
21+
"text/markdown",
22+
"text/csv",
23+
"text/vtt",
2124
"application/javascript",
2225
"application/x-javascript",
2326
"application/json",

‎middleware/compress_test.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ func TestCompressor(t *testing.T) {
109109
}
110110
}
111111

112+
func TestCompressorDefaultTextTypes(t *testing.T) {
113+
for _, contentType := range []string{"text/markdown", "text/csv", "text/vtt"} {
114+
t.Run(contentType, func(t *testing.T) {
115+
r := chi.NewRouter()
116+
r.Use(Compress(5))
117+
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
118+
w.Header().Set("Content-Type", contentType)
119+
w.Write([]byte("textstring"))
120+
})
121+
122+
ts := httptest.NewServer(r)
123+
defer ts.Close()
124+
125+
resp, body := testRequestWithAcceptedEncodings(t, ts, "GET", "/", "gzip")
126+
if body != "textstring" {
127+
t.Errorf("response text doesn't match; expected:%q, got:%q", "textstring", body)
128+
}
129+
if got := resp.Header.Get("Content-Encoding"); got != "gzip" {
130+
t.Errorf("expected encoding %q but got %q", "gzip", got)
131+
}
132+
})
133+
}
134+
}
135+
112136
func TestCompressorWildcards(t *testing.T) {
113137
tests := []struct {
114138
name string

0 commit comments

Comments
 (0)