Skip to content

Instantly share code, notes, and snippets.

@damianh
Created April 18, 2015 09:36
Show Gist options
  • Save damianh/20ac6ba2188f0cc8d4fa to your computer and use it in GitHub Desktop.
Save damianh/20ac6ba2188f0cc8d4fa to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Owin;
using Nowin;
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
internal class Program
{
private static void Main(string[] args)
{
Func<StreamReader, Task<string>> transform = async reader => await reader.ReadToEndAsync();
AppFunc appFunc = async env =>
{
var context = new OwinContext(env);
if(context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
{
using (var writer = new StreamWriter(context.Response.Body))
using (var reader = new StreamReader(context.Request.Body))
{
await writer.WriteAsync(await transform(reader));
}
return;
}
context.Response.StatusCode = 400;
context.Response.ReasonPhrase = "Bad Request";
};
var server = ServerBuilder.New()
.SetEndPoint(new IPEndPoint(IPAddress.Any, 8888))
.SetOwinApp(appFunc)
.Build();
using(server)
{
server.Start();
Console.WriteLine("Server running on http://localhost:8888");
Console.WriteLine("hit to stop");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment