public string ReadAsciiLine()
{
sb.Length = 0;
bool bHadCR = false;
while (true)
{
if (AvailableData == 0)
{
if (ReadRaw() == 0)
// Connection closed while we were waiting for data
throw new IoBroken();
UseLeftOverBytes = true;
}
// Newlines in HTTP headers are expected to be CRLF.
// However, for better robustness, RFC 2616 recommends
// ignoring CR, and considering LF as new lines (section 19.3)
byte b = Buffer[BufferPosition++];
AvailableData--;
if (b == '\n')
break;
if (bHadCR)
sb.Append('\r');
if (b == '\r')
bHadCR = true;
else
{
bHadCR = false;
char c = (char)b;
sb.Append(c);
}
}
return sb.ToString();
}