Skip to content

Commit

Permalink
Fixed cookie not created in owin host
Browse files Browse the repository at this point in the history
  • Loading branch information
majimenezp committed Sep 29, 2011
1 parent 32110eb commit 4b91350
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Nancy.Hosting.Owin.Tests/NancyOwinHostFixture.cs
Expand Up @@ -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);
Expand Down Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion src/Nancy.Hosting.Owin/NancyOwinHost.cs
Expand Up @@ -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);
Expand Down

0 comments on commit 4b91350

Please sign in to comment.