diff --git a/server/gitea/client.go b/server/gitea/client.go index 7037805..9777043 100644 --- a/server/gitea/client.go +++ b/server/gitea/client.go @@ -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) } diff --git a/server/upstream/upstream.go b/server/upstream/upstream.go index 0ecef82..98137ba 100644 --- a/server/upstream/upstream.go +++ b/server/upstream/upstream.go @@ -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 }