Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created April 2, 2013 07:43
Show Gist options
  • Save thecodejunkie/5290587 to your computer and use it in GitHub Desktop.
Save thecodejunkie/5290587 to your computer and use it in GitHub Desktop.
katana host
public class CustomeOwinHost
{
private readonly Func<IDictionary<string, object>, Task> next;
public CustomeOwinHost(Func<IDictionary<string, object>, Task> next, string foo)
{
this.next = next;
}
public Task Invoke(IDictionary<string, object> environment)
{
var path =
environment.Get<string>("owin.RequestPath");
if (path == "/custom")
{
var tcs =
new TaskCompletionSource<int>();
var headers =
environment.Get<IDictionary<string, string[]>>("owin.ResponseHeaders");
headers["Content-Type"] = new [] { "text/html" };
var body =
environment.Get<Stream>("owin.ResponseBody");
using (var writer = new StreamWriter(body))
{
writer.Write("Response from the custom host2.");
}
//tcs.SetResult(0);
return tcs.Task;
}
return next.Invoke(environment);
}
}
@damianh
Copy link

damianh commented Apr 2, 2013

Line 28 is closing the response stream, which is not OWIN compliant http://owin.org/spec/owin-1.0.0.html#_3.5._Response_Body ?

I fixed similar in Nancy NancyFx/Nancy#1016

@Tratcher
Copy link

Tratcher commented Apr 2, 2013

Memory leak! Resources are not cleaned up until the returned task completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment