mirror of
https://github.com/AlexMacocian/MTSC.git
synced 2026-07-15 14:59:33 +00:00
Hello world http module implementation
This commit is contained in:
@@ -26,7 +26,7 @@ namespace MTSC_TestServer
|
||||
.AddLogger(new DebugConsoleLogger())
|
||||
.AddExceptionHandler(new ExceptionConsoleLogger())
|
||||
//.AddHandler(new BroadcastHandler())
|
||||
.AddHandler(new HttpHandler().AddHttpModule(new Http404Module()))
|
||||
.AddHandler(new HttpHandler().AddHttpModule(new HelloWorldModule()))
|
||||
.Run();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MTSC.Server;
|
||||
using MTSC.Server.Handlers;
|
||||
|
||||
namespace MTSC.Common.Http.ServerModules
|
||||
{
|
||||
public class HelloWorldModule : IHttpModule
|
||||
{
|
||||
byte[] response = ASCIIEncoding.ASCII.GetBytes("Hello, World!");
|
||||
bool IHttpModule.HandleRequest(HttpHandler handler, ClientData client, HttpMessage request, ref HttpMessage response)
|
||||
{
|
||||
if (request.Method == HttpMessage.MethodEnum.Get)
|
||||
{
|
||||
//client.ToBeRemoved = true;
|
||||
response.StatusCode = HttpMessage.StatusCodes.OK;
|
||||
response[HttpMessage.GeneralHeadersEnum.Date] = DateTime.Now.ToString();
|
||||
response[HttpMessage.EntityHeadersEnum.ContentType] = "text/plain; charset=UTF-8";
|
||||
response["Server"] = "MTSC";
|
||||
response.Body = this.response;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ namespace MTSC.Common.Http.ServerModules
|
||||
{
|
||||
if(request.Method == HttpMessage.MethodEnum.Get)
|
||||
{
|
||||
response.AddGeneralHeader(HttpMessage.GeneralHeadersEnum.Connection, "keep-alive");
|
||||
//client.ToBeRemoved = true;
|
||||
response.StatusCode = HttpMessage.StatusCodes.NotFound;
|
||||
response[HttpMessage.GeneralHeadersEnum.Date] = DateTime.Now.ToString();
|
||||
|
||||
Reference in New Issue
Block a user