// WithContentType sets both the Content-Type and the X-Content-Type-Options (nosniff) header
339022
func WithContentType(handler http.Handler, contentType string) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", contentType)
		w.Header().Set("X-Content-Type-Options", "nosniff")
		handler.ServeHTTP(w, r)
	})
}
1096298
func OnlyContentTypes(types ...string) Option {
	return func(c *options) error {
		if len(types) == 0 {
			c.contentTypes = nil
			return nil
		}
		c.contentTypes = types
		return nil
	}
}
560237
func (body *Body) ContentType() string {
	if json.Unmarshal(body.Buffer().Bytes(), &struct{}{}) == nil {
		return "application/json"
	}
	return http.DetectContentType(body.Buffer().Bytes())
}
507560
func DataWithContentType(filename string, source io.Reader, contentType string) *BinaryData {
	return &BinaryData{
		Filename:    filename,
		Source:      source,
		ContentType: contentType,
	}
}
794478
func (s *GetSdkOutput) SetContentType(v string) *GetSdkOutput {
	s.ContentType = &v
	return s
}
703117
func (ctx *Context) Type(str string) {
	ctx.Res.Set(HeaderContentType, str)
}
968426
func (s *TransformInput) SetContentType(v string) *TransformInput {
	s.ContentType = &v
	return s
}
836407
func (s *GetObjectInput) SetResponseContentType(v string) *GetObjectInput {
	s.ResponseContentType = &v
	return s
}
1195092
func (r Reader) WriteContentType(w http.ResponseWriter) {
	writeContentType(w, []string{r.ContentType})
}
121255
func isContentTypeAllowed(contentType *string) bool {
	if contentType == nil {
		return false
	}

	allowedContentTypes := []*regexp.Regexp{
		regexp.MustCompile("^text/.+"),
		regexp.MustCompile("^application/json$"),
	}

	for _, r := range allowedContentTypes {
		if r.MatchString(*contentType) {
			return true
		}
	}

	return false
}
466164
func ResolveContentType(req *Request) string {

	contentType := req.Header.Get("Content-Type")
	if contentType == "" {
		return "text/html"
	}
	return strings.ToLower(strings.TrimSpace(strings.Split(contentType, ";")[0]))
}
1228805
func FormatFromContentType(v string) (Format, error) {
	if v == "" {
		return FormatBinary, nil
	}
	mediaType, mediaTypeParams, err := mime.ParseMediaType(v)
	if err != nil {
		return 0, err
	}
	return FormatFromMediaType(mediaType, mediaTypeParams)
}
1048151
func (s *InvokeEndpointOutput) SetContentType(v string) *InvokeEndpointOutput {
	s.ContentType = &v
	return s
}
177347
func AddContentTypes(types ...string) Option {
	return func(c *options) error {
		dst := make([]string, len(c.contentTypes)+len(types))
		copy(dst, c.contentTypes)
		copy(dst[len(c.contentTypes):], types)
		c.contentTypes = dst
		return nil
	}
}
107156
func (s *UpdateModelOutput) SetContentType(v string) *UpdateModelOutput {
	s.ContentType = &v
	return s
}
1102891
func (c Crawler) GetContentType(document *goquery.Document) string {
	var attr string
	// <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	document.Find("meta[http-equiv#=(?i)^Content\\-type$]").Each(func(i int, s *goquery.Selection) {
		attr, _ = s.Attr("content")
	})
	return attr
}
268950
func (r *Request) ExpectContentType(contentType string) *Request {
	r.fallbackContentType = contentType
	return r
}