// 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(ByteArrayHelpers.GetStringFromByteSpan(headerName)); return(true); }
public string GetHeaderValue(ReadOnlySpan <byte> headerValue) { if (headerValue.Length == 0) { return(string.Empty); } // If it's a known header value, use the known value instead of allocating a new string. if (_knownHeader != null && _knownHeader.KnownValues != null) { string[] knownValues = _knownHeader.KnownValues; for (int i = 0; i < knownValues.Length; i++) { if (ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(knownValues[i], headerValue)) { return(knownValues[i]); } } } return(ByteArrayHelpers.GetStringFromByteSpan(headerValue)); }