This project is a .NET Core HTTP server library written in C#.
I decided to create my own HTTP server implementation for at least 3 reasons:
- The native «System.Net.HttpListener» can't be run immediately without administrative privileges
- The native «System.Net.HttpListener» is not really user friendly and quite old
- I wanted to improve my skills on HTTP protocol
- No administrative privileges required
- Simple
- Fast
- Lightweight
- Extensible
- Abstraction for all classes
- Non destructive header parsing
- Transfer Encoding Support (gzip, chunked, deflate)
- Unit tested
Pick the latest nuget at https://www.nuget.org/packages/ElMariachi.Http.Server/
async void Main(string[] args)
{
var serviceProvider = new ServiceCollection()
.AddHttpServer() // Injects the HTTP server implementation in the ServiceCollection
.BuildServiceProvider();
// Create a new server
var httpServer = serviceProvider.GetRequiredService<IHttpServer>();
httpServer.IPAddress = IPAddress.Any;
httpServer.Port = 80;
await httpServer.Start(OnRequest);
}
void OnRequest(IHttpRequest request)
{
request.SendResponse(new HttpResponse(HttpStatus.Ok)
{
Content = new StringResponseContent("Hello World!", "text/plain")
});
}
There are probably plenty of things to do to improve this library, so feel free to contribute.
I spent a lot of my free time to develop this library, so if you like it, feel free to buy me a beer some vegetables ;)