Skip to content

Commit e9cba15

Browse files
committed
Handle pre-gzipped content headers
1 parent 81c46bb commit e9cba15

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ProxySettings struct {
3939
ExtScriptTypes []string `json:"extScriptTypes"`
4040
ExtIndexTypes []string `json:"extIndexTypes"`
4141
ExtMimeTypes map[string]string `json:"extMimeTypes"`
42+
ExtGzippeddTypes []string `json:"extGzippedTypes"`
4243
UseMad4FP bool `json:"useMad4FP"`
4344
LegacyGoPort string `json:"legacyGoPort"`
4445
LegacyPHPPort string `json:"legacyPHPPort"`
@@ -156,12 +157,34 @@ func setContentType(r *http.Request, resp *http.Response) {
156157
if ext != "" {
157158
resp.Header.Set("Content-Type", proxySettings.ExtMimeTypes[ext[1:]])
158159
mime = proxySettings.ExtMimeTypes[ext[1:]]
160+
if mime != "" {
161+
resp.Header.Set("Content-Type", mime)
162+
e := ext[1:]
163+
// If pre-compressed set encoding type
164+
for _, element := range proxySettings.ExtGzippeddTypes {
165+
if element == e {
166+
resp.Header.Set("Content-Encoding", "gzip")
167+
break // String found, no need to continue iterating
168+
}
169+
}
170+
}
159171
}
160172

161173
// If the response has an extension, try and fetch the mime for that via extension
162174
if mime == "" && rext != "" {
163175
resp.Header.Set("Content-Type", proxySettings.ExtMimeTypes[rext[1:]])
164176
mime = proxySettings.ExtMimeTypes[rext[1:]]
177+
if mime != "" {
178+
resp.Header.Set("Content-Type", mime)
179+
e := ext[1:]
180+
// If pre-compressed set encoding type
181+
for _, element := range proxySettings.ExtGzippeddTypes {
182+
if element == e {
183+
resp.Header.Set("Content-Encoding", "gzip")
184+
break // String found, no need to continue iterating
185+
}
186+
}
187+
}
165188
}
166189

167190
// Set content type header

proxySettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"jsp",
2929
"jspx"
3030
],
31+
"extGzippedTypes": [
32+
"svgz"
33+
],
3134
"extMimeTypes": {
3235
"aab": "application/x-authorware-bin",
3336
"aam": "application/x-authorware-map",
@@ -131,6 +134,8 @@
131134
"spl": "application/futuresplash",
132135
"sts": "application/x-squeak-source",
133136
"svf": "vector/x-svf",
137+
"svg": "image/svg+xml",
138+
"svgz": "image/svg+xml",
134139
"svr": "x-world/x-svr",
135140
"swa": "application/x-director",
136141
"swf": "application/x-shockwave-flash",

0 commit comments

Comments
 (0)