Exemple #1
0
        protected ContentDispositionHeaderValue(ContentDispositionHeaderValue source)
        {
            Debug.Assert(source != null);

            _dispositionType = source._dispositionType;
            _parameters      = source._parameters.Clone();
        }
Exemple #2
0
        protected TransferCodingHeaderValue(TransferCodingHeaderValue source)
        {
            Debug.Assert(source != null);

            _value      = source._value;
            _parameters = source._parameters.Clone();
        }
        protected MediaTypeHeaderValue(MediaTypeHeaderValue source)
        {
            Debug.Assert(source != null);

            _mediaType  = source._mediaType;
            _parameters = source._parameters.Clone();
        }
Exemple #4
0
        internal static int GetHashCode(UnvalidatedObjectCollection <NameValueHeaderValue>?values)
        {
            if ((values == null) || (values.Count == 0))
            {
                return(0);
            }

            int result = 0;

            foreach (var value in values)
            {
                result = result ^ value.GetHashCode();
            }
            return(result);
        }
Exemple #5
0
        internal static UnvalidatedObjectCollection <NameValueHeaderValue>?Clone(this UnvalidatedObjectCollection <NameValueHeaderValue>?source)
        {
            if (source == null)
            {
                return(null);
            }

            var copy = new UnvalidatedObjectCollection <NameValueHeaderValue>();

            foreach (NameValueHeaderValue item in source)
            {
                copy.Add(new NameValueHeaderValue(item));
            }

            return(copy);
        }
Exemple #6
0
        internal static NameValueHeaderValue?Find(UnvalidatedObjectCollection <NameValueHeaderValue>?values, string name)
        {
            Debug.Assert((name != null) && (name.Length > 0));

            if ((values == null) || (values.Count == 0))
            {
                return(null);
            }

            foreach (var value in values)
            {
                if (string.Equals(value.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    return(value);
                }
            }
            return(null);
        }
Exemple #7
0
        internal static void ToString(UnvalidatedObjectCollection <NameValueHeaderValue>?values, char separator, bool leadingSeparator,
                                      StringBuilder destination)
        {
            Debug.Assert(destination != null);

            if ((values == null) || (values.Count == 0))
            {
                return;
            }

            foreach (var value in values)
            {
                if (leadingSeparator || (destination.Length > 0))
                {
                    destination.Append(separator);
                    destination.Append(' ');
                }
                value.AddToStringBuilder(destination);
            }
        }
Exemple #8
0
        // Returns the length of a name/value list, separated by 'delimiter'. E.g. "a=b, c=d, e=f" adds 3
        // name/value pairs to 'nameValueCollection' if 'delimiter' equals ','.
        internal static int GetNameValueListLength(string?input, int startIndex, char delimiter,
                                                   UnvalidatedObjectCollection <NameValueHeaderValue> nameValueCollection)
        {
            Debug.Assert(nameValueCollection != null);
            Debug.Assert(startIndex >= 0);

            if ((string.IsNullOrEmpty(input)) || (startIndex >= input.Length))
            {
                return(0);
            }

            int current = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex);

            while (true)
            {
                NameValueHeaderValue?parameter;
                int nameValueLength = NameValueHeaderValue.GetNameValueLength(input, current,
                                                                              s_defaultNameValueCreator, out parameter);

                if (nameValueLength == 0)
                {
                    return(0);
                }

                nameValueCollection.Add(parameter !);
                current = current + nameValueLength;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);

                if ((current == input.Length) || (input[current] != delimiter))
                {
                    // We're done and we have at least one valid name/value pair.
                    return(current - startIndex);
                }

                // input[current] is 'delimiter'. Skip the delimiter and whitespace and try to parse again.
                current++; // skip delimiter.
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);
            }
        }
Exemple #9
0
        internal static void SetQuality(UnvalidatedObjectCollection <NameValueHeaderValue> parameters, double?value)
        {
            Debug.Assert(parameters != null);

            NameValueHeaderValue?qualityParameter = NameValueHeaderValue.Find(parameters, qualityName);

            if (value.HasValue)
            {
                // Note that even if we check the value here, we can't prevent a user from adding an invalid quality
                // value using Parameters.Add(). Even if we would prevent the user from adding an invalid value
                // using Parameters.Add() they could always add invalid values using HttpHeaders.AddWithoutValidation().
                // So this check is really for convenience to show users that they're trying to add an invalid
                // value.
                if ((value < 0) || (value > 1))
                {
                    throw new ArgumentOutOfRangeException(nameof(value));
                }

                string qualityString = ((double)value).ToString("0.0##", NumberFormatInfo.InvariantInfo);
                if (qualityParameter != null)
                {
                    qualityParameter.Value = qualityString;
                }
                else
                {
                    parameters.Add(new NameValueHeaderValue(qualityName, qualityString));
                }
            }
            else
            {
                // Remove quality parameter
                if (qualityParameter != null)
                {
                    parameters.Remove(qualityParameter);
                }
            }
        }
Exemple #10
0
        internal static double?GetQuality(UnvalidatedObjectCollection <NameValueHeaderValue> parameters)
        {
            Debug.Assert(parameters != null);

            NameValueHeaderValue?qualityParameter = NameValueHeaderValue.Find(parameters, qualityName);

            if (qualityParameter != null)
            {
                // Note that the RFC requires decimal '.' regardless of the culture. I.e. using ',' as decimal
                // separator is considered invalid (even if the current culture would allow it).
                double qualityValue;
                if (double.TryParse(qualityParameter.Value, NumberStyles.AllowDecimalPoint,
                                    NumberFormatInfo.InvariantInfo, out qualityValue))
                {
                    return(qualityValue);
                }
                // If the stored value is an invalid quality value, just return null and log a warning.
                if (NetEventSource.Log.IsEnabled())
                {
                    NetEventSource.Error(null, SR.Format(SR.net_http_log_headers_invalid_quality, qualityParameter.Value));
                }
            }
            return(null);
        }
        private CacheControlHeaderValue(CacheControlHeaderValue source)
        {
            Debug.Assert(source != null);

            _noCache         = source._noCache;
            _noStore         = source._noStore;
            _maxAge          = source._maxAge;
            _sharedMaxAge    = source._sharedMaxAge;
            _maxStale        = source._maxStale;
            _maxStaleLimit   = source._maxStaleLimit;
            _minFresh        = source._minFresh;
            _noTransform     = source._noTransform;
            _onlyIfCached    = source._onlyIfCached;
            _publicField     = source._publicField;
            _privateField    = source._privateField;
            _mustRevalidate  = source._mustRevalidate;
            _proxyRevalidate = source._proxyRevalidate;

            if (source._noCacheHeaders != null)
            {
                foreach (var noCacheHeader in source._noCacheHeaders)
                {
                    NoCacheHeaders.Add(noCacheHeader);
                }
            }

            if (source._privateHeaders != null)
            {
                foreach (var privateHeader in source._privateHeaders)
                {
                    PrivateHeaders.Add(privateHeader);
                }
            }

            _extensions = source._extensions.Clone();
        }
Exemple #12
0
 protected NameValueWithParametersHeaderValue(NameValueWithParametersHeaderValue source)
     : base(source)
 {
     _parameters = source._parameters.Clone();
 }