using System; using System.Net; using System.Net.Sockets; namespace HttpServer { /// /// Contains a connection to a browser/client. /// public interface IHttpClientContext { // // // by Fumi.Iseki string SSLCommonName { get; } /// /// Using SSL or other encryption method. /// [Obsolete("Use IsSecured instead.")] bool Secured { get; } /// /// Using SSL or other encryption method. /// bool IsSecured { get; } /// /// Disconnect from client /// /// error to report in the event. void Disconnect(SocketError error); /// /// Send a response. /// /// Either or /// HTTP status code /// reason for the status code. /// HTML body contents, can be null or empty. /// A content type to return the body as, i.e. 'text/html' or 'text/plain', defaults to 'text/html' if null or empty /// If is invalid. void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType); /// /// Send a response. /// /// Either or /// HTTP status code /// reason for the status code. void Respond(string httpVersion, HttpStatusCode statusCode, string reason); /// /// Send a response. /// /// void Respond(string body); /// /// send a whole buffer /// /// buffer to send /// void Send(byte[] buffer); /// /// Send data using the stream /// /// Contains data to send /// Start position in buffer /// number of bytes to send /// /// void Send(byte[] buffer, int offset, int size); /// /// Closes the streams and disposes of the unmanaged resources /// void Close(); bool EndWhenDone { get; set; } /// /// The context have been disconnected. /// /// /// Event can be used to clean up a context, or to reuse it. /// event EventHandler Disconnected; /// /// A request have been received in the context. /// event EventHandler RequestReceived; HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing(); } public class HTTPNetworkContext { public NetworkStream Stream; public Socket Socket; } /// /// A have been disconnected. /// public class DisconnectedEventArgs : EventArgs { /// /// Gets reason to why client disconnected. /// public SocketError Error { get; private set; } /// /// Initializes a new instance of the class. /// /// Reason to disconnection. public DisconnectedEventArgs(SocketError error) { Check.Require(error, "error"); Error = error; } } /// /// /// public class RequestEventArgs : EventArgs { /// /// Gets received request. /// public IHttpRequest Request { get; private set; } /// /// Initializes a new instance of the class. /// /// The request. public RequestEventArgs(IHttpRequest request) { Check.Require(request, "request"); Request = request; } } }