Exemple #1
0
        private async Task <string> Read()
        {
            var contentLength = 0;
            var headerBytes   = await input.ReadToSeparatorAsync(separator);

            while (headerBytes.Length != 0)
            {
                var headerLine = Encoding.ASCII.GetString(headerBytes);
                var position   = headerLine.IndexOf(": ");
                if (position >= 0)
                {
                    var name  = headerLine.Substring(0, position);
                    var value = headerLine.Substring(position + 2);
                    if (string.Equals(name, "Content-Length", StringComparison.Ordinal))
                    {
                        int.TryParse(value, out contentLength);
                    }
                }
                headerBytes = await input.ReadToSeparatorAsync(separator);
            }
            if (contentLength == 0)
            {
                return("");
            }
            var contentBytes = await input.ReadBytesAsync(contentLength);

            return(Encoding.UTF8.GetString(contentBytes));
        }