header.go
func parseMediaType(ctype string) (mtype string, params map[string]string, invalidParams []string, err error) {
	mtype, params, err = mime.ParseMediaType(ctype)
	if err != nil {
		// Small hack to remove harmless charset duplicate params.
		mctype := fixMangledMediaType(ctype, ";")
		mtype, params, err = mime.ParseMediaType(mctype)
		if err != nil {
			// Some badly formed media types forget to send ; between fields.
			mctype := fixMangledMediaType(ctype, " ")
			if strings.Contains(mctype, `name=""`) {
				mctype = strings.Replace(mctype, `name=""`, `name=" "`, -1)
			}
			mtype, params, err = mime.ParseMediaType(mctype)
			if err != nil {
				// If the media parameter has special characters, ensure that it is quoted.
				mtype, params, err = mime.ParseMediaType(fixUnquotedSpecials(mctype))
				if err != nil {
					return "", nil, nil, errors.WithStack(err)
				}
			}
		}
	}
	if mtype == ctPlaceholder {
		mtype = ""
	}
	for name, value := range params {
		if value != pvPlaceholder {
			continue
		}
		invalidParams = append(invalidParams, name)
		delete(params, name)
	}
	return mtype, params, invalidParams, err
}
func parseMediaType(ctype string) (mtype string, params map[string]string, invalidParams []string, err error) {
	mtype, params, err = mime.ParseMediaType(ctype)
	if err != nil {
		// Small hack to remove harmless charset duplicate params.
		mctype := fixMangledMediaType(ctype, ";")
		mtype, params, err = mime.ParseMediaType(mctype)
		if err != nil {
			// Some badly formed media types forget to send ; between fields.
			mctype := fixMangledMediaType(ctype, " ")
			if strings.Contains(mctype, `name=""`) {
				mctype = strings.Replace(mctype, `name=""`, `name=" "`, -1)
			}
			mtype, params, err = mime.ParseMediaType(mctype)
			if err != nil {
				// If the media parameter has special characters, ensure that it is quoted.
				mtype, params, err = mime.ParseMediaType(fixUnquotedSpecials(mctype))
				if err != nil {
					return "", nil, nil, errors.WithStack(err)
				}
			}
		}
	}
	if mtype == ctPlaceholder {
		mtype = ""
	}
	for name, value := range params {
		if value != pvPlaceholder {
			continue
		}
		invalidParams = append(invalidParams, name)
		delete(params, name)
	}
	return mtype, params, invalidParams, err
}
// parseMediaType is a more tolerant implementation of Go's mime.ParseMediaType function.