Skip to content
Browse files

Merge pull request #318 from majimenezp/master

Fix: Cookie not created in OWIN host
  • Loading branch information...
2 parents ffae3dd + 4b91350 commit d8557cf82cab4100a022de27c6bdc5a15d159d56 @grumpydev grumpydev committed Sep 30, 2011
Showing with 20 additions and 1 deletion.
  1. +16 −0 src/Nancy.Hosting.Owin.Tests/NancyOwinHostFixture.cs
  2. +4 −1 src/Nancy.Hosting.Owin/NancyOwinHost.cs
View
16 src/Nancy.Hosting.Owin.Tests/NancyOwinHostFixture.cs
@@ -36,6 +36,7 @@ public NancyOwinHostFixture()
this.fakeEngine = A.Fake<INancyEngine>();
this.fakeBootstrapper = A.Fake<INancyBootstrapper>();
+
A.CallTo(() => this.fakeBootstrapper.GetEngine()).Returns(this.fakeEngine);
this.host = new NancyOwinHost(fakeBootstrapper);
@@ -302,6 +303,21 @@ public void Should_read_entire_request_body_when_there_is_a_continuation()
output.ShouldEqual("This is some request body content");
}
+ [Fact]
+ public void Should_set_cookie_with_valid_header()
+ {
+ var fakeResponse = new Response() { StatusCode = HttpStatusCode.OK };
+ fakeResponse.AddCookie("test", "testvalue");
+ var fakeContext = new NancyContext() { Response = fakeResponse };
+
+ this.SetupFakeNancyCompleteCallback(fakeContext);
+ var respHeaders = new Dictionary<string, string>();
+ ResponseCallBack callback = (status, headers, bodyDelegate) =>respHeaders=(Dictionary<string,string>)headers;
+
+ this.host.ProcessRequest(environment, callback, fakeErrorCallback);
+ respHeaders.ContainsKey("Set-Cookie").ShouldBeTrue();
+ (respHeaders["Set-Cookie"]=="test=testvalue; path=/").ShouldBeTrue();
+ }
/// <summary>
/// Sets the fake nancy engine to execute the complete callback with the given context
/// </summary>
View
5 src/Nancy.Hosting.Owin/NancyOwinHost.cs
@@ -143,7 +143,10 @@ private void InvokeNancy(NancyRequestParameters parameters, ResponseCallBack res
{
var returnCode = GetReturnCode(result);
var headers = result.Response.Headers;
-
+ foreach (var cookie in result.Response.Cookies)
+ {
+ headers.Add("Set-Cookie", cookie.ToString());
+ }
responseCallBack.Invoke(returnCode, headers, GetResponseBodyBuilder(result));
},
errorCallback);

0 comments on commit d8557cf

Please sign in to comment.
Something went wrong with that request. Please try again.