UHTTPd.NET
micro HTTP server library and application for local development & testing. Highly extensible, built-in static file handling & directory listing as well as arbitrary action per endpoint
Install / Use
/learn @migajek/UHTTPd.NETREADME
µHTTPd .NET
Micro HTTP server library & application.
for local development & testing only
Features
- high performance (async/await-based)
- painfully simple to use
- built-in static file serving
- built-in directory listing
- built-in "delegate" handler for registering C# routine for specific route
Quick start
- download & reference the library
- Add following code:
var http = new uHttpServer();
http.InitDefaults(@"C:\test\"); // OPTIONAL: add static file handler and directory listing handler for given root directory, add an exception handler
http.Start("http://localhost:8090/"); // start listening on localhost:8090
Reference
Custom routes actions
Instead of serving static files, we'll use C# code for generating response
var http = new uHttpServer();
http.Handlers.Add(new DelegateWithParamsHandler(@"^/hello,{name:\w+}$",
delegate(HttpListenerRequest request,HttpListenerResponse response, Dictionary<string, string> dictionary)
{
response.ContentType = "text/html";
return String.Format("Hi there, <b>{0}</b>", dictionary["name"]);
}));
http.Start("http://localhost:8090/");
now, point your browser to http://localhost:8090/hello,mike
What you'll see is: Hi there, mike
Exception handling
Built-in DefaultHttpExceptionHandler is enabled by default when InitDefaults is called.
The DefaultHttpExceptionHandler translates every HTTP exception into the proper HTTP status code, and displays the error header.
Optionally, stack trace displaying might be enabled:
http.ExceptionHandlers.OfType<DefaultHttpExceptionHandler>().Single().ShowStackTrace = true;
To-do
Please be aware that this project is not intended to compete with production servers; instead it's supposed to be as easy and simple as possible.
- logging (NLog / log4net)
- wrap response object into custom class for more control over StatusCode and ContentType
- request & response filters
- serving embedded resources
Features not being considered currently:
- authentication
- fastcgi
License
Feel free to use under MIT license, just let me know if you find it useful.
Copyright 2014 Michał Gajek "migajek"
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
