mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-19 12:54:24 +02: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
|
||||
}
|
||||
|
||||
func (client *Client) getMimeTypeByExtension(resource string) (string, string) {
|
||||
func (client *Client) getMimeTypeByExtension(resource string) (mimeType, rawType string) {
|
||||
rawExt := path.Ext(resource)
|
||||
innerExt := rawExt
|
||||
switch rawExt {
|
||||
case ".gz":
|
||||
fallthrough
|
||||
case ".br":
|
||||
fallthrough
|
||||
case ".zst":
|
||||
case ".gz", ".br", ".zst":
|
||||
innerExt = path.Ext(resource[:len(resource)-len(rawExt)])
|
||||
}
|
||||
rawType := client.extToMime(rawExt)
|
||||
mimeType := rawType
|
||||
rawType = client.extToMime(rawExt)
|
||||
mimeType = rawType
|
||||
if innerExt != rawExt {
|
||||
mimeType = client.extToMime(innerExt)
|
||||
}
|
||||
|
|
|
@ -73,13 +73,12 @@ func AcceptEncodings(header string) []string {
|
|||
qualities := make(map[string]float64)
|
||||
|
||||
for _, encoding := range strings.Split(header, ",") {
|
||||
splits := strings.SplitN(encoding, ";q=", 2)
|
||||
name := splits[0]
|
||||
name, quality_str, has_quality := strings.Cut(encoding, ";q=")
|
||||
quality := 1.0
|
||||
|
||||
if len(splits) > 1 {
|
||||
if has_quality {
|
||||
var err error
|
||||
quality, err = strconv.ParseFloat(splits[1], 64)
|
||||
quality, err = strconv.ParseFloat(quality_str, 64)
|
||||
if err != nil || quality < 0 {
|
||||
continue
|
||||
}
|
||||
|
@ -120,7 +119,7 @@ func AcceptEncodings(header string) []string {
|
|||
// sort in reverse order; big quality comes first
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue