private void SearchForHeaderTerminator( byte[] data )
{
for ( int i = 0; i < data.Length && !_foundHeaderTerminator; i++ )
{
if ( data[i] == '\r' )
{
_consecutiveCrCount++;
}
else if ( data[i] == '\n' )
{
_consecutiveLfCount++;
}
else
{
_consecutiveCrCount = 0;
_consecutiveLfCount = 0;
}
if ( _consecutiveCrCount == 2
&& _consecutiveLfCount == 2 )
{
_foundHeaderTerminator = true;
_headerData.Write( data, 0, i + 1 );
// Write any remaining data to the body memory buffer
if ( data.Length
> i + 1 )
{
_bodyData = new MemoryStream( data.Length - i - 1 );
_bodyData.Write( data, i + 1, data.Length - i - 1 );
}
}
}
if ( !_foundHeaderTerminator )
{
_headerData.Write( data, 0, data.Length );
}
// TODO: research why this fires the event too many times
//if (!_foundHeaderTerminator)
//{
// _context.OnAdditionalDataRequested();
//}
}