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); }
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); }
// 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); }
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); }
// 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; }