void RequestHandler(IHttpClientContext client, IHttpRequest request)
{
HttpResponse response = new HttpResponse(client, request);
// Create a request signature
HttpRequestSignature signature = new HttpRequestSignature(request);
// Look for a signature match in our handlers
for (int i = 0; i < requestHandlers.Length; i++)
{
HttpRequestHandler handler = requestHandlers[i];
if (handler.Signature != null && signature == handler.Signature)
{
FireRequestCallback(client, request, response, handler.Callback);
return;
}
}
// No registered handler matched this request's signature
if (notFoundHandler != null)
{
FireRequestCallback(client, request, response, notFoundHandler);
}
else
{
// Send a default 404 response
try
{
response.Status = HttpStatusCode.NotFound;
response.Reason = String.Format("No request handler registered for Method=\"{0}\", Content-Type=\"{1}\", Path=\"{2}\"",
signature.Method, signature.ContentType, signature.Path);
string notFoundResponse = "<html><head><title>Page Not Found</title></head><body><h3>" + response.Reason + "</h3></body></html>";
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundResponse);
response.Body.Write(buffer, 0, buffer.Length);
response.Send();
}
catch (Exception) { }
}
}