// returns true if we've been configured to compress the specific content type.
17288
func (o options) shouldCompress(contentType string, statusCode int) bool {
	// If contentTypes is nil we handle all content types.
	if len(o.contentTypes) > 0 {
		ct := strings.ToLower(contentType)
		ct = strings.Split(ct, ";")[0]
		found := false
		for _, v := range o.contentTypes {
			if strings.HasPrefix(ct, v) {
				found = true
				break
			}
		}
		if !found {
			return false
		}
	}
	if len(o.statusCodes) > 0 {
		_, ok := o.statusCodes[statusCode]
		if !ok {
			return false
		}
	}

	return true
}
576914
func isLikeMediaType(s, t string) bool {
	if !strings.HasPrefix(s, "application/") {
		return false
	}
	switch t {
	case "json":
		return strings.Contains(s, "+json")
	case "xml":
		return strings.Contains(s, "+xml")
	default:
		return false
	}
}
623692
func DetectCompression(source []byte) Compression {
	for compression, m := range map[Compression][]byte{
		Bzip2: {0x42, 0x5A, 0x68},
		Gzip:  {0x1F, 0x8B, 0x08},
		Xz:    {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
	} {
		if len(source) < len(m) {
			logrus.Debugf("Len too short")
			continue
		}
		if bytes.Compare(m, source[:len(m)]) == 0 {
			return compression
		}
	}
	return Uncompressed
}
1014233
func CompressContent(content []byte) []byte {
	var buf bytes.Buffer
	zipWriter := gzip.NewWriter(&buf)

	_, err := zipWriter.Write(content)
	if err != nil {
		log.Warnf("Error in compressing: %v", err)
	}
	close(zipWriter)
	return buf.Bytes()
}
502768
func (x *Xz) Compress(in io.Reader, out io.Writer) error {
	w, err := xz.NewWriter(out)
	if err != nil {
		return err
	}
	defer w.Close()
	_, err = io.Copy(w, in)
	return err
}
521217
func (s *CacheBehavior) SetCompress(v bool) *CacheBehavior {
	s.Compress = &v
	return s
}
1210013
func (gz *Gz) Compress(in io.Reader, out io.Writer) error {
	w, err := gzip.NewWriterLevel(out, gz.CompressionLevel)
	if err != nil {
		return err
	}
	defer w.Close()
	_, err = io.Copy(w, in)
	return err
}
61945
func excludeForCompression(header http.Header, object string) bool {
	objStr := object
	contentType := header.Get("Content-Type")
	if globalIsCompressionEnabled {
		// We strictly disable compression for standard extensions/content-types (`compressed`).
		if hasStringSuffixInSlice(objStr, standardExcludeCompressExtensions) || hasPattern(standardExcludeCompressContentTypes, contentType) {
			return true
		}
		// Filter compression includes.
		if len(globalCompressExtensions) > 0 || len(globalCompressMimeTypes) > 0 {
			extensions := globalCompressExtensions
			mimeTypes := globalCompressMimeTypes
			if hasStringSuffixInSlice(objStr, extensions) || hasPattern(mimeTypes, contentType) {
				return false
			}
			return true
		}
		return false
	}
	return true
}
661399
func IsCompressedDiff(ctx context.Context, mediaType string) (bool, error) {
	switch mediaType {
	case ocispec.MediaTypeImageLayer, MediaTypeDockerSchema2Layer:
	case ocispec.MediaTypeImageLayerGzip, MediaTypeDockerSchema2LayerGzip:
		return true, nil
	default:
		// Still apply all generic media types *.tar[.+]gzip and *.tar
		if strings.HasSuffix(mediaType, ".tar.gzip") || strings.HasSuffix(mediaType, ".tar+gzip") {
			return true, nil
		} else if !strings.HasSuffix(mediaType, ".tar") {
			return false, errdefs.ErrNotImplemented
		}
	}
	return false, nil
}
840648
func (b *RouteBuilder) ContentEncodingEnabled(enabled bool) *RouteBuilder {
	b.contentEncodingEnabled = &enabled
	return b
}
730438
func (s SnappyCompressor) Compress(w io.Writer) (io.WriteCloser, error) {
	return snappy.NewBufferedWriter(w), nil
}
844958
func ContentType(name string) string {
	contenttype := ""
	ext := filepath.Ext(name)
	if contenttype == "" {
		contenttype = mime.TypeByExtension(ext)
		if contenttype == "" {
			contenttype = "application/octet-stream"
		}
	}
	return contenttype
}
350274
func String2CompressionType(s string) CompressionType {

	switch s {
	case CompressionTypeV1.toString():
		return CompressionTypeV1
	case CompressionTypeV2.toString():
		return CompressionTypeV2
	default:
		return CompressionTypeNone
	}
}
215427
func (m *MockEncoder) IsCompressionEnabled() bool {
	ret := m.ctrl.Call(m, "IsCompressionEnabled")
	ret0, _ := ret[0].(bool)
	return ret0
}
1241363
func Codec(contentType string, c encoding.Codec) server.Option {
	return func(o *server.Options) {
		codecs := make(map[string]encoding.Codec)
		if o.Context == nil {
			o.Context = context.Background()
		}
		if v := o.Context.Value(codecsKey{}); v != nil {
			codecs = v.(map[string]encoding.Codec)
		}
		codecs[contentType] = c
		o.Context = context.WithValue(o.Context, codecsKey{}, codecs)
	}
}
230725
func (ctx *context) Gzip(enable bool) {
	if enable {
		if ctx.ClientSupportsGzip() {
			_ = ctx.GzipResponseWriter()
		}
	} else {
		if gzipResWriter, ok := ctx.writer.(*GzipResponseWriter); ok {
			gzipResWriter.Disable()
		}
	}
}
129747
func (r *URIBuilder) ContentType(s string) *URIBuilder {
	r.cacheContentType = s
	return r
}