protected void OnFirstLine(string value)
{
//
//todo: In the interest of robustness, servers SHOULD ignore any empty line(s) received where a Request-Line is expected.
// In other words, if the server is reading the protocol stream at the beginning of a message and receives a CRLF first, it should ignore the CRLF.
//
_log.Write(this, LogPrio.Debug, "Got request: " + value);
//Request-Line = Method SP Request-URI SP HTTP-Version CRLF
int pos = value.IndexOf(' ');
if (pos == -1 || pos + 1 >= value.Length)
{
_log.Write(this, LogPrio.Warning, "Invalid request line, missing Method. Line: " + value);
throw new BadRequestException("Invalid request line, missing Method. Line: " + value);
}
CurrentRequest.Method = value.Substring(0, pos).ToUpper();
int oldPos = pos + 1;
pos = value.IndexOf(' ', oldPos);
if (pos == -1)
{
_log.Write(this, LogPrio.Warning, "Invalid request line, missing URI. Line: " + value);
throw new BadRequestException("Invalid request line, missing URI. Line: " + value);
}
CurrentRequest.UriPath = value.Substring(oldPos, pos - oldPos);
if (CurrentRequest.UriPath.Length > 4196)
throw new BadRequestException("Too long uri.");
if (pos + 1 >= value.Length)
{
_log.Write(this, LogPrio.Warning, "Invalid request line, missing HTTP-Version. Line: " + value);
throw new BadRequestException("Invalid request line, missing HTTP-Version. Line: " + value);
}
CurrentRequest.HttpVersion = value.Substring(pos + 1);
if (CurrentRequest.HttpVersion.Length < 4 || string.Compare(CurrentRequest.HttpVersion.Substring(0, 4), "HTTP", true) != 0)
{
_log.Write(this, LogPrio.Warning, "Invalid HTTP version in request line. Line: " + value);
throw new BadRequestException("Invalid HTTP version in Request line. Line: " + value);
}
}