/// <summary> /// Determines whether the stream starts with the given string. /// </summary> /// <param name="clientStreamReader">The client stream reader.</param> /// <param name="expectedStart">The expected start.</param> /// <returns> /// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise /// </returns> private static async Task <int> startsWith(ICustomStreamReader clientStreamReader, string expectedStart) { bool isExpected = true; int legthToCheck = 10; for (int i = 0; i < legthToCheck; i++) { int b = await clientStreamReader.PeekByteAsync(i); if (b == -1) { return(-1); } if (b == ' ' && i > 2) { return(isExpected ? 1 : 0); } char ch = (char)b; if (!char.IsLetter(ch)) { return(-1); } if (i >= expectedStart.Length || ch != expectedStart[i]) { isExpected = false; } } // only letters return(isExpected ? 1 : 0); }
internal async Task <bool> EnsureBufferLength(int length, CancellationToken cancellationToken) { var val = await baseStream.PeekByteAsync(Position + length - 1, cancellationToken); return(val != -1); }
public Task <int> PeekByteAsync(int index, CancellationToken cancellationToken = default) { return(reader.PeekByteAsync(index, cancellationToken)); }