Example #1
0
        private async Task <byte[]> ReadBodyAsync(int contentLength, CancellationToken cancellationToken)
        {
            byte[] body;

            if (contentLength == -1)
            {
                body = await _reader.ReadBytesUntilAsync(0, cancellationToken);
            }
            else
            {
                body = new byte[contentLength];

                int byteCount = await _reader.ReadBytesAsync(body, 0, contentLength, cancellationToken);

                if (byteCount != contentLength)
                {
                    throw new InvalidDataException("Body actual length is different from content-length (=" + StompHeaders.ContentLength + ").");
                }

                byte b = await _reader.ReadByteAsync(cancellationToken);

                if (b != 0)
                {
                    throw new InvalidDataException("Body is not NULL terminated.");
                }
            }

            return(body);
        }
Example #2
0
        private async Task <byte[]> ReadBodyAsync(int contentLength, CancellationToken cancellationToken)
        {
            byte[] body;

            if (contentLength == -1)
            {
                body = await _reader.ReadBytesUntilAsync(0, cancellationToken);
            }
            else
            {
                body = new byte[contentLength];

                await _reader.ReadNBytesAsync(body, 0, contentLength, cancellationToken);

                byte b = await _reader.ReadByteAsync(cancellationToken);

                if (b != 0)
                {
                    throw new InvalidDataException("Body is not NULL terminated.");
                }
            }

            return(body);
        }