File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,15 @@ func isCompressibleType(contentType string) bool {
1717 return true
1818 }
1919
20+ sepIndex := strings .IndexByte (contentType , ';' )
21+ if sepIndex > 0 {
22+ contentType = contentType [:sepIndex ]
23+ }
24+
2025 // "image/svg+xml", "application/xhtml+xml", ...
2126 if strings .HasSuffix (contentType , "+xml" ) {
2227 return true
2328 }
2429
25- sepIndex := strings .IndexByte (contentType , ';' )
26- if sepIndex > 0 {
27- contentType = contentType [:sepIndex ]
28- }
2930 return util .Contains (compressibleTypes , contentType )
3031}
Original file line number Diff line number Diff line change 1+ package serverCompress
2+
3+ import "testing"
4+
5+ func TestIsCompressibleType (t * testing.T ) {
6+ if ! isCompressibleType ("text/plain" ) {
7+ t .Error ()
8+ }
9+ if ! isCompressibleType ("text/plain; charset=utf-8" ) {
10+ t .Error ()
11+ }
12+
13+ if ! isCompressibleType ("image/svg+xml" ) {
14+ t .Error ()
15+ }
16+ if ! isCompressibleType ("image/svg+xml; charset=utf-8" ) {
17+ t .Error ()
18+ }
19+ if isCompressibleType ("image/png" ) {
20+ t .Error ()
21+ }
22+ if isCompressibleType ("image/png; foo=bar" ) {
23+ t .Error ()
24+ }
25+
26+ if ! isCompressibleType ("application/javascript" ) {
27+ t .Error ()
28+ }
29+ if ! isCompressibleType ("application/javascript; charset=utf-8" ) {
30+ t .Error ()
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments