5 using System.Collections.Concurrent;
6 using System.Collections.Generic;
8 using System.Threading;
17 private static string urlEncodedHeader =
"application/x-www-form-urlencoded";
18 private static string multipartHeader =
"multipart/form-data";
20 List<IHttpModule> httpModules =
new List<IHttpModule>();
21 ConcurrentQueue<Tuple<ClientData,HttpMessage>> messageQueue =
new ConcurrentQueue<Tuple<ClientData, HttpMessage>>();
29 #region Public Methods 37 this.httpModules.Add(module);
46 messageQueue.Enqueue(
new Tuple<ClientData, HttpMessage>(client, response));
49 #region Interface Implementation 73 bool IHandler.HandleReceivedMessage(Server server, ClientData client,
Message message)
79 httpMessage[
HttpMessage.GeneralHeadersEnum.Connection].ToLower() ==
"close")
81 responseMessage[
HttpMessage.GeneralHeadersEnum.Connection] =
"close";
82 client.ToBeRemoved =
true;
86 responseMessage[
HttpMessage.GeneralHeadersEnum.Connection] =
"keep-alive";
90 if(module.
HandleRequest(server,
this, client, httpMessage, ref responseMessage))
104 bool IHandler.HandleSendMessage(Server server, ClientData client, ref Message message)
114 bool IHandler.PreHandleReceivedMessage(Server server, ClientData client, ref Message message)
121 void IHandler.Tick(Server server)
123 while (messageQueue.Count > 0)
125 Tuple<ClientData, HttpMessage> tuple =
null;
126 if (messageQueue.TryDequeue(out tuple))
128 server.QueueMessage(tuple.Item1, tuple.Item2.BuildResponse(
true));
133 module.
Tick(server,
this);
void QueueResponse(ClientData client, HttpMessage response)
Send a response back to the client.
Interface for communication handlers.
void Tick(Server.Server server, HttpHandler handler)
Perform periodic operations.
Structure containing client information.
Handler for handling server http requests.
void ClientRemoved(Server server, ClientData client)
Handles the removal of a client from the server.
Basic server class to handle TCP connections.
bool ContainsHeader(ResponseHeadersEnum header)
Check if the message contains a header.
bool HandleRequest(Server.Server server, HttpHandler handler, ClientData client, HttpMessage request, ref HttpMessage response)
Handle the received request.
HttpHandler AddHttpModule(IHttpModule module)
Add a http module onto the server.
void ParseRequest(byte[] requestBytes)
Parse the received bytes and populate the message contents.
Interface for Http modules used by the server http handler.