Griffin.Net.Protocols.Http.HttpMessageEncoder.Prepare C# (CSharp) Method

Prepare() public method

Are about to send a new message
Can be used to prepare the next message. for instance serialize it etc.
Message is of a type that the encoder cannot handle.
public Prepare ( object message ) : void
message object Message to send
return void
        public void Prepare(object message)
        {
            if (!(message is HttpMessage))
                throw new InvalidOperationException("This encoder only supports messages deriving from 'HttpMessage'");

            _message = (HttpMessage) message;
            if (_message.Body == null || _message.Body.Length == 0)
                _message.Headers["Content-Length"] = "0";
            else if (_message.ContentLength == 0)
            {
                _message.ContentLength = (int)_message.Body.Length;
                if (_message.Body.Position == _message.Body.Length)
                    _message.Body.Position = 0;
            }

        }

Usage Example

Ejemplo n.º 1
0
        public void basic_response()
        {
            var frame = new HttpResponse(404, "Failed to find it dude", "HTTP/1.1");
            var expected = "HTTP/1.1 404 Failed to find it dude\r\n";
            var buffer = new SocketBufferFake();

            var encoder = new HttpMessageEncoder();
            encoder.Prepare(frame);
            encoder.Send(buffer);
            var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);

            actual.Substring(0,expected.Length).Should().Be(expected);
        }
All Usage Examples Of Griffin.Net.Protocols.Http.HttpMessageEncoder::Prepare