项目作者: dajuric

项目描述 :
Simple, portable HTTP server for .NET based on HttpListener.
高级语言: C#
项目地址: git://github.com/dajuric/simple-http.git
创建时间: 2018-01-02T18:34:37Z
项目社区:https://github.com/dajuric/simple-http

开源协议:Other

下载



SimpleHTTP logo


NuGet packages version

SimpleHTTP - HTTP server for .NET
Lightweight HTTP server for .NET written based on System.Net.HttpListener. Supports partial file streaming, file caching (ETag), simple templating, single-pass form parsing (no temp file).

Tutorial: CodeProject article

Why SimpleHTTP ?

  • Lightweight
    No dependencies.

  • Simple
    There is only one relevant method Route.Add which associates a route with an action.
    Other methods are extensions on HttpListenerRequest and HttpListenerResponse classes.
    Zero configuration.

Sample

The snippets below demonstrate the most common functionality. For a demonstration of the all functionalities check the sample.

  1. //rq - request, rp -response, args - arguments
  2. //Route.Add(...) serves "GET" requests by default
  3. //1) serve file (supports video streaming)
  4. Route.Add("/{file}", (rq, rp, args) => rp.AsFile(rq, args["file"]));
  5. //2) return text with a cookie if a path matches a condition
  6. Route.Add((rq, args) => rq.Url.LocalPath.ToLower().EndsWith("helloworld"),
  7. (rq, rp, args) => rp.WithCookie("myCookie", "myContent")
  8. .AsText("Hello world!"));
  9. //3) parse body (fields and files)
  10. Route.Add("/myForm/", (rq, rp, args) =>
  11. {
  12. var files = rq.ParseBody(args);
  13. //save files
  14. foreach (var f in files.Values)
  15. f.Save(f.FileName);
  16. //write form-fields
  17. foreach (var a in args)
  18. Console.WriteLine(a.Key + " " + a.Value);
  19. rp.AsText(String.Empty);
  20. },
  21. "POST");
  22. //run the server
  23. Server.ListenAsync(8000, CancellationToken.None, Route.OnHttpRequestAsync)
  24. .Wait();

WebSocketRPC library

How to Engage, Contribute and Provide Feedback

Remember: Your opinion is important and will define the future roadmap.

  • questions, comments - Github
  • spread the word

Final word

If you like the project please star it in order to help to spread the word. That way you will make the framework more significant and in the same time you will motivate me to improve it, so the benefit is mutual.