// Quality returns the quality of a content type based on the media ranges in h.
347332
func (h AcceptHeader) Quality(contentType string, params map[string][]string) float64 {
	results := make(mediaRangeMatches, 0, len(h))
	for i := range h {
		mr := &h[i]
		if m := mr.match(contentType, params); m.Valid {
			results = append(results, m)
		}
	}
	if len(results) == 0 {
		return 0.0
	}

	// find most specific
	i := 0
	for j := 1; j < results.Len(); j++ {
		if results.Less(j, i) {
			i = j
		}
	}
	return results[i].MediaRange.Quality
}
617675
func (s *MgetService) Pretty(pretty bool) *MgetService {
	s.pretty = pretty
	return s
}
718290
func (s *ClusterRerouteService) Pretty(pretty bool) *ClusterRerouteService {
	s.pretty = pretty
	return s
}
208068
func FormatFromMediaType(mt string, params map[string]string) (Format, error) {
	switch mt {
	case ContentTypePRPC:
		for k := range params {
			if k != mtPRPCEncoding {
				return 0, fmt.Errorf("unexpected parameter %q", k)
			}
		}
		return FormatFromEncoding(params[mtPRPCEncoding])

	case ContentTypeJSON:
		return FormatJSONPB, nil

	case "", "*/*", "application/*", "application/grpc":
		return FormatBinary, nil

	default:
		return 0, fmt.Errorf("unknown content type: %q", mt)
	}
}
1145134
func (h Header) parseMediaType(typeField string) (string, map[string]string, error) {
	if content := h.Get(typeField); len(content) > 0 {
		mediaType, mediaTypeParams, err := mime.ParseMediaType(content)
		if err != nil {
			return "", map[string]string{}, err
		}
		return mediaType, mediaTypeParams, nil
	}
	return "", map[string]string{}, ErrHeadersMissingField
}
567743
func JPEGEncoder(quality int) Encoder {
	return func(w io.Writer, img image.Image) error {
		return jpeg.Encode(w, img, &jpeg.Options{Quality: quality})
	}
}
363845
func (mr *MediaRange) Match(contentType string, params map[string][]string) bool {
	return mr.match(contentType, params).Valid
}
1016777
func (c *Context) Type() string {
	head := c.Request().Header().Get("Content-Type")
	cont, _, _ := mime.ParseMediaType(head)
	return cont
}
175248
func (s *CatHealthService) Pretty(pretty bool) *CatHealthService {
	s.pretty = pretty
	return s
}
349132
func Codec(contentType string, c codec.NewCodec) Option {
	return func(o *Options) {
		o.Codecs[contentType] = c
	}
}
950885
func (s *FaceDetail) SetQuality(v *ImageQuality) *FaceDetail {
	s.Quality = v
	return s
}
1178054
func (s *IndicesGetSettingsService) Pretty(pretty bool) *IndicesGetSettingsService {
	s.pretty = pretty
	return s
}
513845
func (s *IndicesGetMappingService) Pretty(pretty bool) *IndicesGetMappingService {
	s.pretty = pretty
	return s
}
803762
func (f Format) MediaType() string {
	switch f {
	case FormatJSONPB:
		return mtPRPCJSONPB
	case FormatText:
		return mtPRPCText
	case FormatBinary:
		fallthrough
	default:
		return mtPRPCBinary
	}
}
250490
func (s *SnapshotDeleteRepositoryService) Pretty(pretty bool) *SnapshotDeleteRepositoryService {
	s.pretty = pretty
	return s
}
1127439
func isContentType(h http.Header, contentType string) bool {
	ct := h.Get("Content-Type")
	if i := strings.IndexRune(ct, ';'); i != -1 {
		ct = ct[0:i]
	}
	return ct == contentType
}
630353
func parseMediaRange(mediaRange string) (rangeParams, typeSubtype []string, err error) {
	rangeParams = strings.Split(mediaRange, ";")
	typeSubtype = strings.Split(rangeParams[0], "/")

	// typeSubtype should have a length of exactly two.
	if len(typeSubtype) > 2 {
		err = fmt.Errorf(errInvalidTypeSubtype, rangeParams[0])
		return
	} else {
		typeSubtype = append(typeSubtype, "*")
	}

	// Sanitize typeSubtype.
	typeSubtype[0] = strings.TrimSpace(typeSubtype[0])
	typeSubtype[1] = strings.TrimSpace(typeSubtype[1])
	if typeSubtype[0] == "" {
		typeSubtype[0] = "*"
	}
	if typeSubtype[1] == "" {
		typeSubtype[1] = "*"
	}

	return
}