Esempio n. 1
0
        /// <summary>
        /// Determines whether is connect method.
        /// </summary>
        /// <param name="clientStream">The client stream.</param>
        /// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
        internal static async Task <int> IsConnectMethod(CustomBufferedStream clientStream)
        {
            bool isConnect    = true;
            int  legthToCheck = 10;

            for (int i = 0; i < legthToCheck; i++)
            {
                int b = await clientStream.PeekByteAsync(i);

                if (b == -1)
                {
                    return(-1);
                }

                if (b == ' ' && i > 2)
                {
                    // at least 3 letters and a space
                    return(isConnect ? 1 : 0);
                }

                char ch = (char)b;
                if (!char.IsLetter(ch))
                {
                    // non letter or too short
                    return(-1);
                }

                if (i > 6 || ch != "CONNECT"[i])
                {
                    isConnect = false;
                }
            }

            // only letters
            return(isConnect ? 1 : 0);
        }
Esempio n. 2
0
        public async Task <bool> EnsureBufferLength(int length)
        {
            var val = await baseStream.PeekByteAsync(Position + length - 1);

            return(val != -1);
        }