Esempio n. 1
0
        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)
            {
                if (_knownHeader.KnownValues != null)
                {
                    string[] knownValues = _knownHeader.KnownValues;
                    for (int i = 0; i < knownValues.Length; i++)
                    {
                        if (ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(knownValues[i], headerValue))
                        {
                            return(knownValues[i]);
                        }
                    }
                }

                if (_knownHeader == KnownHeaders.Location)
                {
                    // Normally Location should be in ISO-8859-1 but occasionally some servers respond with UTF-8.
                    if (TryDecodeUtf8(headerValue, out string decoded))
                    {
                        return(decoded);
                    }
                }
            }

            return(HttpRuleParser.DefaultHttpEncoding.GetString(headerValue));
        }
Esempio n. 2
0
        internal static unsafe KnownHeader TryGetKnownHeader(ReadOnlySpan <byte> name)
        {
            fixed(byte *p = &MemoryMarshal.GetReference(name))
            {
                KnownHeader candidate = GetCandidate(new BytePtrAccessor(p, name.Length));

                if (candidate != null && ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(candidate.Name, name))
                {
                    return(candidate);
                }
            }

            return(null);
        }
Esempio n. 3
0
        internal unsafe static KnownHeader TryGetKnownHeader(ReadOnlySpan <byte> name)
        {
            fixed(byte *p = &name.DangerousGetPinnableReference())
            {
                KnownHeader candidate = GetCandidate(new BytePtrAccessor(p, name.Length));

                if (candidate != null && ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(candidate.Name, name))
                {
                    return(candidate);
                }
            }

            return(null);
        }
Esempio n. 4
0
        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(HttpRuleParser.DefaultHttpEncoding.GetString(headerValue));
        }