예제 #1
0
        internal override bool IsAllowedHeaderName(HeaderDescriptor descriptor)
        {
            if (!_containsTrailingHeaders)
            {
                return(true);
            }

            KnownHeader knownHeader = KnownHeaders.TryGetKnownHeader(descriptor.Name);

            if (knownHeader == null)
            {
                return(true);
            }

            return((knownHeader.HeaderType & HttpHeaderType.NonTrailing) == 0);
        }
예제 #2
0
        internal static IEnumerable <KeyValuePair <HeaderDescriptor, string[]> > GetHeaderDescriptorsAndValues(this HttpHeaders headers)
        {
            List <KeyValuePair <HeaderDescriptor, string[]> > result = new List <KeyValuePair <HeaderDescriptor, string[]> >();

            foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
            {
                KnownHeader knownHeader = KnownHeaders.TryGetKnownHeader(header.Key);
                if (knownHeader == null)
                {
                    knownHeader = new KnownHeader(header.Key);
                }
                HeaderDescriptor descriptor = new HeaderDescriptor(knownHeader);
                result.Add(new KeyValuePair <HeaderDescriptor, string[]>(descriptor, header.Value.ToArray()));
            }

            return(result);
        }
예제 #3
0
        // Returns false for invalid header name.
        public static bool TryGet(ReadOnlySpan <byte> headerName, out HeaderDescriptor descriptor)
        {
            Debug.Assert(headerName.Length > 0);

            KnownHeader?knownHeader = KnownHeaders.TryGetKnownHeader(headerName);

            if (knownHeader != null)
            {
                descriptor = new HeaderDescriptor(knownHeader);
                return(true);
            }

            if (!HttpRuleParser.IsToken(headerName))
            {
                descriptor = default(HeaderDescriptor);
                return(false);
            }

            descriptor = new HeaderDescriptor(HttpRuleParser.GetTokenString(headerName));
            return(true);
        }
예제 #4
0
        public override bool Equals(object?obj) => throw new InvalidOperationException();    // Ensure this is never called, to avoid boxing

        // Returns false for invalid header name.
        public static bool TryGet(string headerName, out HeaderDescriptor descriptor)
        {
            Debug.Assert(!string.IsNullOrEmpty(headerName));

            KnownHeader?knownHeader = KnownHeaders.TryGetKnownHeader(headerName);

            if (knownHeader != null)
            {
                descriptor = new HeaderDescriptor(knownHeader);
                return(true);
            }

            if (!HttpRuleParser.IsToken(headerName))
            {
                descriptor = default(HeaderDescriptor);
                return(false);
            }

            descriptor = new HeaderDescriptor(headerName);
            return(true);
        }
예제 #5
0
 // This should not be used directly; use static TryGet below
 internal HeaderDescriptor(string headerName, bool customHeader = false)
 {
     Debug.Assert(customHeader || KnownHeaders.TryGetKnownHeader(headerName) is null, $"The {nameof(KnownHeader)} overload should be used for {headerName}");
     _descriptor = headerName;
 }