ronantakizawa/codereview-bench huggingface dataset:
Repository: traefik/traefik
File: pkg/muxer/http/matcher_v2.go (Go)

Code before:
	"HostRegexp":    hostRegexpV2,
	"ClientIP":      clientIPV2,
	"Path":          pathV2,
	"PathPrefix":    pathPrefixV2,
	"Method":        methodsV2,
	"Headers":       headersV2,
	"HeadersRegexp": headersRegexpV2,
	"Query":         queryV2,
}

func pathV2(tree *matchersTree, paths ...string) error {
	var routes []*mux.Route

	for _, path := range paths {
		route := mux.NewRouter().NewRoute()

		if err := route.Path(path).GetError(); err != nil {
			return err
		}

		routes = append(routes, route)
	}

	tree.matcher = func(req *http.Request) bool {
		for _, sb := range routes {
			if sb.Match(req, &mux.RouteMatch{}) {
				return true
			}
		}

		return false
	}

	return nil
}

func pathPrefixV2(tree *matchersTree, paths ...string) error {
	var routes []*mux.Route

	for _, path := range paths {
		route := mux.NewRouter().NewRoute()

		if err := route.PathPrefix(path).GetError(); err != nil {
			return err
		}

		routes = append(routes, route)
	}

	tree.matcher = func(req *http.Request) bool {
		for _, sb := range routes {

Review comment (suggestion):
nitpick:
```suggestion
		for _, route := range routes {
			if route.Match(req, &mux.RouteMatch{}) {
```

Code after:
	"HostRegexp":    hostRegexpV2,
	"ClientIP":      clientIPV2,
	"Path":          pathV2,
	"PathPrefix":    pathPrefixV2,
	"Method":        methodsV2,
	"Headers":       headersV2,
	"HeadersRegexp": headersRegexpV2,
	"Query":         queryV2,
}

func pathV2(tree *matchersTree, paths ...string) error {
	var routes []*mux.Route

	for _, path := range paths {
		route := mux.NewRouter().NewRoute()

		if err := route.Path(path).GetError(); err != nil {
			return err
		}

		routes = append(routes, route)
	}

	tree.matcher = func(req *http.Request) bool {
		for _, route := range routes {
			if route.Match(req, &mux.RouteMatch{}) {
				return true
			}
		}

		return false
	}

	return nil
}

func pathPrefixV2(tree *matchersTree, paths ...string) error {
	var routes []*mux.Route

	for _, path := range paths {
		route := mux.NewRouter().NewRoute()

		if err := route.PathPrefix(path).GetError(); err != nil {
			return err
		}

		routes = append(routes, route)
	}

	tree.matcher = func(req *http.Request) bool {
		for _, route := range routes {
Repository: traefik/traefik
File: pkg/provider/acme/provider.go (Go)

Code before:
						domain := types.Domain{
							Main: validDomains[0],
						}
						if len(validDomains) > 0 {
							domain.SANs = validDomains[1:]
						}

						err = p.addCertificateForDomain(domain, cert, traefiktls.DefaultTLSStoreName)
						if err != nil {
							logger.WithError(err).Error("Error adding certificate for domain")
						}
					})
				}
			case <-ctxPool.Done():
				return
			}
		}
	})
}

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	domainKey := strings.Join(domains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range domains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(domains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", domains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,

Review comment (suggestion):
Hello @Lamatte,

Thanks for this contribution!
I think the sorting should be kept here as well, but done as in the certExists func to avoid it to mutate the domains slice for the certificate order.

Code after:
						domain := types.Domain{
							Main: validDomains[0],
						}
						if len(validDomains) > 0 {
							domain.SANs = validDomains[1:]
						}

						err = p.addCertificateForDomain(domain, cert, traefiktls.DefaultTLSStoreName)
						if err != nil {
							logger.WithError(err).Error("Error adding certificate for domain")
						}
					})
				}
			case <-ctxPool.Done():
				return
			}
		}
	})
}

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range domains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(domains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", domains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
Repository: traefik/traefik
File: pkg/provider/acme/provider.go (Go)

Code before:
			case <-ctxPool.Done():
				return
			}
		}
	})
}

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range sortedDomains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(sortedDomains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", sortedDomains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", sortedDomains, err)
	}
	if cert == nil {

Review comment (suggestion):
```suggestion
	for _, certDomain := range domains {
```

Code after:
			case <-ctxPool.Done():
				return
			}
		}
	})
}

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range domains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(domains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", domains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", domains, err)
	}
	if cert == nil {
Repository: traefik/traefik
File: pkg/provider/acme/provider.go (Go)

Code before:

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range sortedDomains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(sortedDomains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", sortedDomains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", sortedDomains, err)
	}
	if cert == nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v", sortedDomains)
	}
	if len(cert.Certificate) == 0 || len(cert.PrivateKey) == 0 {
		return nil, fmt.Errorf("certificate for domains %v is empty: %v", sortedDomains, cert)
	}


Review comment (suggestion):
```suggestion
	defer p.removeResolvingDomains(append(domains, domainKey))
```

Code after:

func (p *Provider) resolveDefaultCertificate(ctx context.Context, domains []string) (*certificate.Resource, error) {
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range domains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(domains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", domains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", domains, err)
	}
	if cert == nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v", domains)
	}
	if len(cert.Certificate) == 0 || len(cert.PrivateKey) == 0 {
		return nil, fmt.Errorf("certificate for domains %v is empty: %v", domains, cert)
	}
Repository: traefik/traefik
File: pkg/provider/acme/provider.go (Go)

Code before:
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range sortedDomains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(sortedDomains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", sortedDomains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", sortedDomains, err)
	}
	if cert == nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v", sortedDomains)
	}
	if len(cert.Certificate) == 0 || len(cert.PrivateKey) == 0 {
		return nil, fmt.Errorf("certificate for domains %v is empty: %v", sortedDomains, cert)
	}

	logger.Debugf("Default certificate obtained for domains %+v", sortedDomains)


Review comment (bug):
```suggestion
	logger.Debugf("Loading ACME certificates %+v...", domains)
```

Code after:
	logger := log.FromContext(ctx)

	p.resolvingDomainsMutex.Lock()

	sortedDomains := make([]string, len(domains))
	copy(sortedDomains, domains)
	sort.Strings(sortedDomains)

	domainKey := strings.Join(sortedDomains, ",")

	if _, ok := p.resolvingDomains[domainKey]; ok {
		p.resolvingDomainsMutex.Unlock()
		return nil, nil
	}

	p.resolvingDomains[domainKey] = struct{}{}

	for _, certDomain := range domains {
		p.resolvingDomains[certDomain] = struct{}{}
	}

	p.resolvingDomainsMutex.Unlock()

	defer p.removeResolvingDomains(append(domains, domainKey))

	logger.Debugf("Loading ACME certificates %+v...", domains)

	client, err := p.getClient()
	if err != nil {
		return nil, fmt.Errorf("cannot get ACME client %w", err)
	}

	request := certificate.ObtainRequest{
		Domains:        domains,
		Bundle:         true,
		PreferredChain: p.PreferredChain,
	}

	cert, err := client.Certificate.Obtain(request)
	if err != nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v: %w", domains, err)
	}
	if cert == nil {
		return nil, fmt.Errorf("unable to generate a certificate for the domains %v", domains)
	}
	if len(cert.Certificate) == 0 || len(cert.PrivateKey) == 0 {
		return nil, fmt.Errorf("certificate for domains %v is empty: %v", domains, cert)
	}

	logger.Debugf("Default certificate obtained for domains %+v", domains)
Repository: traefik/traefik
File: pkg/middlewares/compress/acceptencoding_test.go (Go)

Code before:
package compress

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc     string
		values   []string
		expected string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "unknown compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression types (no weight) use default",
			values:   []string{"compress, rar"},
			expected: "foo",
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
		{
			desc:     "ignore unknown compression type",
			values:   []string{"compress;q=1.0, gzip;q=0.5"},
			expected: gzipName,
		},
		{
			desc:     "not acceptable (identity)",

Review comment (suggestion):
```suggestion
			desc:     "known compression type (no weight)",
```

Code after:
package compress

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc        string
		values      []string
		defaultType string
		expected    string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "known compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression type (no weight), no encoding",
			values:   []string{"compress, rar"},
			expected: identityName,
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:        "wildcard return the custom default compression type",
			values:      []string{"*"},
			defaultType: "foo",
			expected:    "foo",
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
Repository: traefik/traefik
File: pkg/middlewares/compress/acceptencoding_test.go (Go)

Code before:
package compress

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc     string
		values   []string
		expected string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "unknown compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression types (no weight) use default",
			values:   []string{"compress, rar"},
			expected: "foo",
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
		{
			desc:     "ignore unknown compression type",
			values:   []string{"compress;q=1.0, gzip;q=0.5"},
			expected: gzipName,
		},
		{
			desc:     "not acceptable (identity)",
			values:   []string{"compress;q=1.0, identity;q=0"},
			expected: notAcceptable,
		},
		{
			desc:     "not acceptable (wildcard)",

Review comment (suggestion):
```suggestion
			desc:     "unknown compression types, use default (no weight)",
```

Code after:
package compress

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc        string
		values      []string
		defaultType string
		expected    string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "known compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression type (no weight), no encoding",
			values:   []string{"compress, rar"},
			expected: identityName,
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:        "wildcard return the custom default compression type",
			values:      []string{"*"},
			defaultType: "foo",
			expected:    "foo",
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
		{
			desc:     "ignore unknown compression type",
			values:   []string{"compress;q=1.0, gzip;q=0.5"},
			expected: gzipName,
		},
Repository: traefik/traefik
File: pkg/middlewares/compress/acceptencoding_test.go (Go)

Code before:

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc        string
		values      []string
		defaultType string
		expected    string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "known compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression types, use default (no weight)",
			values:   []string{"compress, rar"},
			expected: identityName,
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:        "wildcard return the custom default compression type",
			values:      []string{"*"},
			defaultType: "foo",
			expected:    "foo",
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
		{
			desc:     "ignore unknown compression type",
			values:   []string{"compress;q=1.0, gzip;q=0.5"},
			expected: gzipName,
		},
		{

Review comment (suggestion):
```suggestion
			desc:     "unknown compression type (no weight), no encoding",
```

Code after:

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getCompressionType(t *testing.T) {
	testCases := []struct {
		desc        string
		values      []string
		defaultType string
		expected    string
	}{
		{
			desc:     "br > gzip (no weight)",
			values:   []string{"gzip, br"},
			expected: brotliName,
		},
		{
			desc:     "known compression type (no weight)",
			values:   []string{"compress, gzip"},
			expected: gzipName,
		},
		{
			desc:     "unknown compression type (no weight), no encoding",
			values:   []string{"compress, rar"},
			expected: identityName,
		},
		{
			desc:     "wildcard return the default compression type",
			values:   []string{"*"},
			expected: brotliName,
		},
		{
			desc:        "wildcard return the custom default compression type",
			values:      []string{"*"},
			defaultType: "foo",
			expected:    "foo",
		},
		{
			desc:     "follows weight",
			values:   []string{"br;q=0.8, gzip;q=1.0, *;q=0.1"},
			expected: gzipName,
		},
		{
			desc:     "ignore unknown compression type",
			values:   []string{"compress;q=1.0, gzip;q=0.5"},
			expected: gzipName,
		},
		{
Repository: traefik/traefik
File: pkg/middlewares/compress/acceptencoding.go (Go)

Code before:

		if encoding.Type == wildcardName && encoding.Weight != nil && *encoding.Weight == 0 {
			return notAcceptable
		}

		if encoding.Type == wildcardName {
			return defaultType
		}

		return encoding.Type
	}

	for _, dt := range []string{brotliName, gzipName} {
		if slices.ContainsFunc(encodings, func(e Encoding) bool { return e.Type == dt }) {
			return dt
		}
	}

	if slices.ContainsFunc(encodings, func(e Encoding) bool { return e.Type == wildcardName }) {
		return defaultType
	}

	return identityName
}

func parseAcceptsEncoding(acceptEncoding []string) ([]Encoding, bool) {
	var encodings []Encoding
	var hasWeight bool

	for _, line := range acceptEncoding {
		for _, item := range strings.Split(strings.ReplaceAll(line, " ", ""), ",") {
			parsed := strings.SplitN(item, ";", 2)
			if len(parsed) == 0 {
				continue
			}

			switch parsed[0] {
			case brotliName, gzipName, identityName, wildcardName:
				// supported encoding
			default:
				continue
			}

			var weight *float64
			if len(parsed) > 1 && strings.HasPrefix(parsed[1], "q=") {
				w, _ := strconv.ParseFloat(strings.TrimPrefix(parsed[1], "q="), 64)

				weight = &w
				hasWeight = true
			}


Review comment (suggestion):
```suggestion
func parseAcceptEncoding(acceptEncoding []string) ([]Encoding, bool) {
```

Code after:

		if encoding.Type == wildcardName && encoding.Weight != nil && *encoding.Weight == 0 {
			return notAcceptable
		}

		if encoding.Type == wildcardName {
			return defaultType
		}

		return encoding.Type
	}

	for _, dt := range []string{brotliName, gzipName} {
		if slices.ContainsFunc(encodings, func(e Encoding) bool { return e.Type == dt }) {
			return dt
		}
	}

	if slices.ContainsFunc(encodings, func(e Encoding) bool { return e.Type == wildcardName }) {
		return defaultType
	}

	return identityName
}

func parseAcceptEncoding(acceptEncoding []string) ([]Encoding, bool) {
	var encodings []Encoding
	var hasWeight bool

	for _, line := range acceptEncoding {
		for _, item := range strings.Split(strings.ReplaceAll(line, " ", ""), ",") {
			parsed := strings.SplitN(item, ";", 2)
			if len(parsed) == 0 {
				continue
			}

			switch parsed[0] {
			case brotliName, gzipName, identityName, wildcardName:
				// supported encoding
			default:
				continue
			}

			var weight *float64
			if len(parsed) > 1 && strings.HasPrefix(parsed[1], "q=") {
				w, _ := strconv.ParseFloat(strings.TrimPrefix(parsed[1], "q="), 64)

				weight = &w
				hasWeight = true
			}