mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-05-12 04:57:50 +00:00
Review fixes
This commit is contained in:
parent
1c0ce28d8e
commit
e34d5275d6
2 changed files with 8 additions and 13 deletions
|
@ -315,19 +315,15 @@ func (client *Client) extToMime(ext string) string {
|
||||||
return mimeType
|
return mimeType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) getMimeTypeByExtension(resource string) (string, string) {
|
func (client *Client) getMimeTypeByExtension(resource string) (mimeType, rawType string) {
|
||||||
rawExt := path.Ext(resource)
|
rawExt := path.Ext(resource)
|
||||||
innerExt := rawExt
|
innerExt := rawExt
|
||||||
switch rawExt {
|
switch rawExt {
|
||||||
case ".gz":
|
case ".gz", ".br", ".zst":
|
||||||
fallthrough
|
|
||||||
case ".br":
|
|
||||||
fallthrough
|
|
||||||
case ".zst":
|
|
||||||
innerExt = path.Ext(resource[:len(resource)-len(rawExt)])
|
innerExt = path.Ext(resource[:len(resource)-len(rawExt)])
|
||||||
}
|
}
|
||||||
rawType := client.extToMime(rawExt)
|
rawType = client.extToMime(rawExt)
|
||||||
mimeType := rawType
|
mimeType = rawType
|
||||||
if innerExt != rawExt {
|
if innerExt != rawExt {
|
||||||
mimeType = client.extToMime(innerExt)
|
mimeType = client.extToMime(innerExt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,13 +73,12 @@ func AcceptEncodings(header string) []string {
|
||||||
qualities := make(map[string]float64)
|
qualities := make(map[string]float64)
|
||||||
|
|
||||||
for _, encoding := range strings.Split(header, ",") {
|
for _, encoding := range strings.Split(header, ",") {
|
||||||
splits := strings.SplitN(encoding, ";q=", 2)
|
name, quality_str, has_quality := strings.Cut(encoding, ";q=")
|
||||||
name := splits[0]
|
|
||||||
quality := 1.0
|
quality := 1.0
|
||||||
|
|
||||||
if len(splits) > 1 {
|
if has_quality {
|
||||||
var err error
|
var err error
|
||||||
quality, err = strconv.ParseFloat(splits[1], 64)
|
quality, err = strconv.ParseFloat(quality_str, 64)
|
||||||
if err != nil || quality < 0 {
|
if err != nil || quality < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -120,7 +119,7 @@ func AcceptEncodings(header string) []string {
|
||||||
// sort in reverse order; big quality comes first
|
// sort in reverse order; big quality comes first
|
||||||
return cmp.Compare(qualities[y], qualities[x])
|
return cmp.Compare(qualities[y], qualities[x])
|
||||||
})
|
})
|
||||||
log.Trace().Msgf("decided encoding order: %#v", encodings)
|
log.Trace().Msgf("decided encoding order: %v", encodings)
|
||||||
return encodings
|
return encodings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue