Exemple #1
0
        /// <summary>
        ///  Initializes a new instance of the <see cref="HttpHeadersMatcher"/> class using specified header <paramref name="name"/>.
        /// </summary>
        /// <param name="name">The header name to match.</param>
        public HttpHeadersMatcher(string name) : base(new HttpHeadersCollection())
        {
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            _equalityComparer = new HttpHeaderEqualityComparer(true);
            Value.TryAddWithoutValidation(name, (string)null);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpHeadersMatcher"/> class using specified header <paramref name="name"/> and <paramref name="values"/>.
        /// </summary>
        /// <param name="name">The header name to match.</param>
        /// <param name="values">The header values to match.</param>
        public HttpHeadersMatcher(string name, IEnumerable <string> values)
            : base(new HttpHeadersCollection())
        {
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            _equalityComparer = new HttpHeaderEqualityComparer();

            Value.Add(name, values);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpHeadersMatcher"/> class using specified <paramref name="headers"/>.
        /// </summary>
        /// <param name="headers">The headers to match.</param>
        public HttpHeadersMatcher(IEnumerable <KeyValuePair <string, IEnumerable <string> > > headers)
            : base(new HttpHeadersCollection())
        {
            if (headers is null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            _equalityComparer = new HttpHeaderEqualityComparer();

            foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
            {
                Value.Add(header.Key, header.Value);
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpHeadersMatcher"/> class using specified header <paramref name="name"/> and <paramref name="value"/>.
        /// </summary>
        /// <param name="name">The header name to match.</param>
        /// <param name="value">The header value to match.</param>
        /// <param name="allowWildcards"><see langword="true"/> to allow wildcards, or <see langword="false"/> if exact matching.</param>
        public HttpHeadersMatcher(string name, string value, bool allowWildcards = false)
            : base(new HttpHeadersCollection())
        {
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            RegexPatternMatcher patternMatcher = allowWildcards ? new RegexPatternMatcher(value) : null;

            _equalityComparer = patternMatcher == null
                                ? new HttpHeaderEqualityComparer()
                                : new HttpHeaderEqualityComparer(patternMatcher);

            Value.Add(name, value);
        }