using System;
using OSHttpServer.Exceptions;
using OSHttpServer.Parser;
namespace OSHttpServer
{
///
/// Event driven parser used to parse incoming HTTP requests.
///
///
/// The parser supports partial messages and keeps the states between
/// each parsed buffer. It's therefore important that the parser gets
/// ed if a client disconnects.
///
public interface IHttpRequestParser
{
///
/// Current state in parser.
///
RequestParserState CurrentState { get; }
///
/// Parse partial or complete message.
///
/// buffer containing incoming bytes
/// where in buffer that parsing should start
/// number of bytes to parse
/// Unparsed bytes left in buffer.
/// BadRequestException.
int Parse(byte[] buffer, int offset, int count);
///
/// A request have been successfully parsed.
///
event EventHandler RequestCompleted;
///
/// More body bytes have been received.
///
event EventHandler BodyBytesReceived;
///
/// Request line have been received.
///
event EventHandler RequestLineReceived;
///
/// A header have been received.
///
event EventHandler HeaderReceived;
///
/// Clear parser state.
///
void Clear();
///
/// Gets or sets the log writer.
///
ILogWriter LogWriter { get; set; }
}
///
/// Current state in the parsing.
///
public enum RequestParserState
{
///
/// Should parse the request line
///
FirstLine,
///
/// Searching for a complete header name
///
HeaderName,
///
/// Searching for colon after header name (ignoring white spaces)
///
AfterName,
///
/// Searching for start of header value (ignoring white spaces)
///
Between,
///
/// Searching for a complete header value (can span over multiple lines, as long as they are prefixed with one/more whitespaces)
///
HeaderValue,
///
/// Adding bytes to body
///
Body
}
}