HttpServer.HttpRequest.AddToBody C# (CSharp) Method

AddToBody() public method

Add bytes to the body
If body is not writable
public AddToBody ( byte bytes, int offset, int length ) : int
bytes byte buffer to read bytes from
offset int where to start read
length int number of bytes to read
return int
        public int AddToBody(byte[] bytes, int offset, int length)
        {
            if (bytes == null)
                throw new ArgumentNullException("bytes");
            if (offset + length > bytes.Length)
                throw new ArgumentOutOfRangeException("offset");
            if (length == 0)
                return 0;
            if (!_body.CanWrite)
                throw new InvalidOperationException("Body is not writable.");

            if (length > _bodyBytesLeft)
            {
                length = _bodyBytesLeft;
            }

            _body.Write(bytes, offset, length);
            _bodyBytesLeft -= length;

            return length;
        }

Usage Example

Example #1
0
 /// <summary>
 /// Process incoming body bytes.
 /// </summary>
 /// <param name="sender"><see cref="IHttpRequestParser"/></param>
 /// <param name="e">Bytes</param>
 protected virtual void OnBodyBytesReceived(object sender, BodyEventArgs e)
 {
     m_currentRequest.AddToBody(e.Buffer, e.Offset, e.Count);
 }