private void InterpretHttpHeaders( HttpHeaders headers, string httpVersion )
{
Contract.Requires(!string.IsNullOrEmpty(httpVersion));
int length = 0;
string contentLength = headers["content-length"];
if ( contentLength != null )
{
length = int.Parse( contentLength );
}
string transferEncoding = headers["transfer-encoding"];
if ( transferEncoding != null
&& transferEncoding.ToLower().Contains( "chunked" ) )
{
_context.State = new ReadChunkedHeaderState( _context );
if ( _bodyData.Length > 0 )
{
_context.State.AcceptData( _bodyData.ToArray() );
}
else
{
_context.OnAdditionalDataRequested();
}
}
else if ( length > 0 )
{
_context.State = new ReadNormalBodyState( _context, length );
if ( _bodyData.Length > 0 )
{
_context.State.AcceptData( _bodyData.ToArray() );
}
else
{
_context.OnAdditionalDataRequested();
}
}
// HTTP 1.0 assumes non-persistent connection (connection=close unnecessary)
// HTTP 1.1 assumes persistent connection. Unless the connection is explictly closed, assume no body
// if content-length is not specified.
else if ( contentLength == null && (httpVersion == "1.0" || headers["connection"] == "close" ))
{
_context.State = new ReadHttp10BodyState(_context);
_context.State.AcceptData(_bodyData.ToArray());
}
else
{
_context.OnMessageReadComplete();
// 0-byte message. Start reading the next header.
_context.State = new ReadHeaderState(_context);
_context.OnAdditionalDataRequested();
}
}