Created
April 2, 2013 07:43
-
-
Save thecodejunkie/5290587 to your computer and use it in GitHub Desktop.
katana host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
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
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