Skip to content

Commit

Permalink
Handle pre-gzipped content headers
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Oct 28, 2023
1 parent 81c46bb commit e9cba15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ProxySettings struct {
ExtScriptTypes []string `json:"extScriptTypes"`
ExtIndexTypes []string `json:"extIndexTypes"`
ExtMimeTypes map[string]string `json:"extMimeTypes"`
ExtGzippeddTypes []string `json:"extGzippedTypes"`
UseMad4FP bool `json:"useMad4FP"`
LegacyGoPort string `json:"legacyGoPort"`
LegacyPHPPort string `json:"legacyPHPPort"`
Expand Down Expand Up @@ -156,12 +157,34 @@ func setContentType(r *http.Request, resp *http.Response) {
if ext != "" {
resp.Header.Set("Content-Type", proxySettings.ExtMimeTypes[ext[1:]])
mime = proxySettings.ExtMimeTypes[ext[1:]]
if mime != "" {
resp.Header.Set("Content-Type", mime)
e := ext[1:]
// If pre-compressed set encoding type
for _, element := range proxySettings.ExtGzippeddTypes {
if element == e {
resp.Header.Set("Content-Encoding", "gzip")
break // String found, no need to continue iterating
}
}
}
}

// If the response has an extension, try and fetch the mime for that via extension
if mime == "" && rext != "" {
resp.Header.Set("Content-Type", proxySettings.ExtMimeTypes[rext[1:]])
mime = proxySettings.ExtMimeTypes[rext[1:]]
if mime != "" {
resp.Header.Set("Content-Type", mime)
e := ext[1:]
// If pre-compressed set encoding type
for _, element := range proxySettings.ExtGzippeddTypes {
if element == e {
resp.Header.Set("Content-Encoding", "gzip")
break // String found, no need to continue iterating
}
}
}
}

// Set content type header
Expand Down
5 changes: 5 additions & 0 deletions proxySettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"jsp",
"jspx"
],
"extGzippedTypes": [
"svgz"
],
"extMimeTypes": {
"aab": "application/x-authorware-bin",
"aam": "application/x-authorware-map",
Expand Down Expand Up @@ -131,6 +134,8 @@
"spl": "application/futuresplash",
"sts": "application/x-squeak-source",
"svf": "vector/x-svf",
"svg": "image/svg+xml",
"svgz": "image/svg+xml",
"svr": "x-world/x-svr",
"swa": "application/x-director",
"swf": "application/x-shockwave-flash",
Expand Down

0 comments on commit e9cba15

Please sign in to comment.