Exemple #1
0
        public static void AnalyzeResponseLine(ReadOnlySpan <char> line, Clients.Response response)
        {
            int offset = 0;
            int count  = 0;

            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == ' ')
                {
                    if (count == 0)
                    {
                        response.HttpVersion = new string(line.Slice(offset, i - offset));
                        offset = i + 1;
                    }
                    else
                    {
                        response.Code    = new string(line.Slice(offset, i - offset));
                        offset           = i + 1;
                        response.CodeMsg = new string(line.Slice(offset, line.Length - offset));
                        return;
                    }
                    count++;
                }
            }
        }
        private void loadChunkedData(PipeStream stream)
        {

        Next:
            string line;
            if (chunkeLength > 0)
            {
                if (pipeStream == null)
                    pipeStream = new PipeStream();
                while (true)
                {
                    byte[] buffer = HttpParse.GetByteBuffer();
                    int count = buffer.Length;
                    if (count > chunkeLength)
                        count = chunkeLength;
                    int read = stream.Read(buffer, 0, count);
                    if (read == 0)
                        return;
                    pipeStream.Write(buffer, 0, read);
                    chunkeLength -= read;
                    if (chunkeLength == 0)
                    {
                        chunkeLength = 0;
                        break;
                    }
                }
            }
            else
            {
                if (!stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out line))
                    return;
                if (string.IsNullOrEmpty(line))
                {
                    if (end)
                    {
                        var item = response;
                        pipeStream.Flush();
                        item.Stream = pipeStream;
                        response = null;
                        pipeStream = null;
                        end = false;
                        Completed?.Invoke(Client, item);
                        return;
                    }
                    else
                    {
                        goto Next;
                    }
                }
                else
                {
                    try
                    {
                        chunkeLength = int.Parse(line, System.Globalization.NumberStyles.HexNumber);
                        if (chunkeLength == 0)
                        {
                            end = true;
                        }
                        else
                            response.Length += chunkeLength;
                    }
                    catch (Exception e_)
                    {
                        throw e_;
                    }
                }
            }
            if (stream.Length > 0)
                goto Next;
        }