Пример #1
0
 public static async Task ParseHeaders(Stream input, Stream output, HttpRequestData data)
 {
     var @continue = false;
     do
     {
         @continue = await ParseHeaderLine(input, output, data);
     } while (@continue);
 }
Пример #2
0
        public HttpRequest(Stream input)
        {
            Input = input;
            BufferFirstLine = new MemoryStream();
            BufferHeaders = new MemoryStream();
            BufferAppendHeaders = new MemoryStream();

            Data = new HttpRequestData();
        }
Пример #3
0
        public static async Task StreamResponse(Stream input, Stream output)
        {
            await ReadUntil(input, output, ' ', true, 20);
            await ReadUntil(input, output, ' ', true, 10);
            await ReadUntilLineEnd(input, output, true, 100);

            HttpRequestData data = new HttpRequestData();

            await ParseHeaders(input, output, data);
            await input.CopyToAsync(output, data.ContentLength.Value);
        }
Пример #4
0
        public static async Task<bool> ParseHeaderLine(Stream input, Stream output, HttpRequestData data)
        {
            var name = await ReadUntil(input, output, ' ', ':', '\r', '\n', false, 100);

            if (string.IsNullOrEmpty(name))
            {
                return false;
            }

            await ReadWhile(input, output, ' ', true, 100);

            var value = await ReadUntilLineEnd(input, output, false, 1024);

            if (name == "Host")
            {
                data.Host = value;
            }
            else if (name == "Content-Length")
            {
                data.ContentLength = long.Parse(value);
            }

            return true;
        }
Пример #5
0
 public static async Task ParseRequestFirstLine(Stream input, Stream output, HttpRequestData data)
 {
     data.Method = await ReadUntil(input, output, ' ', true, 20);
     data.Uri = await ReadUntil(input, output, ' ', true, 1000 * 10);
     data.Version = await ReadUntilLineEnd(input, output, true, 100);
 }