public static HeaderValuesWithQualityCollection Parse(string headerValue)
        {
            var result = new HeaderValuesWithQualityCollection();

            if (string.IsNullOrEmpty(headerValue))
            {
                return(result);
            }

            if (!valueFormat.IsMatch(headerValue))
            {
                throw new FormatException($"Invalid header value: '{headerValue}'.");
            }

            var headerValueParts = headerValue.Split(valueSeparator, StringSplitOptions.RemoveEmptyEntries);

            foreach (var valueWithQuality in headerValueParts)
            {
                var valueQuality = valueWithQuality.Split(qualitySeparator, StringSplitOptions.RemoveEmptyEntries);
                if (valueQuality.Length < 1 || valueQuality.Length > 2)
                {
                    throw new FormatException($"Invalid header value format at '{valueWithQuality}'");
                }

                var     value = valueQuality.FirstOrDefault();
                decimal quality;
                if (valueQuality.Length < 2 || !decimal.TryParse(valueQuality[1].Split(qualityValueSeparator, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(), NumberStyles.Number, NumberFormatInfo.InvariantInfo, out quality))
                {
                    quality = 1m;
                }
                result.Add(value, quality);
            }
            return(result);
        }
        public static Request AppendToHeaderWithQuality([NotNull] this Request request, [NotNull] string name, [NotNull] string value, decimal quality = 1)
        {
            var currentValue = request.Headers?[name];

            if (string.IsNullOrEmpty(currentValue))
            {
                return(request.WithHeader(name, new HeaderValueWithQuality(value, quality)));
            }

            var valueCollection = HeaderValuesWithQualityCollection.Parse(currentValue);

            valueCollection.Add(value, quality);
            return(request.WithHeader(name, valueCollection.ToString()));
        }