Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Fix for issue #680 + another fix #722

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Nancy.Hosting.Aspnet/NancyHandler.cs
Expand Up @@ -99,14 +99,18 @@ private static void SetNancyResponseToHttpResponse(HttpContextBase context, Resp
response.Contents.Invoke(context.Response.OutputStream);
}

/// <remarks>
/// Copies are made of each collection (Headers, Cookies) for enumeration to avoid
/// InvalidOperationExceptions if ASP.NET modifies the response on a different thread.
/// </remarks>
private static void SetHttpResponseHeaders(HttpContextBase context, Response response)
{
foreach (var header in response.Headers)
foreach (var header in response.Headers.ToDictionary(x => x.Key, x => x.Value))
{
context.Response.AddHeader(header.Key, header.Value);
}

foreach(var cookie in response.Cookies)
foreach (var cookie in response.Cookies.ToList())
{
context.Response.AddHeader("Set-Cookie", cookie.ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nancy/Routing/DefaultRouteResolver.cs
Expand Up @@ -50,7 +50,7 @@ public ResolveResult Resolve(NancyContext context)

if (!string.IsNullOrEmpty(extension))
{
var length = context.Request.Path.Length - (extension.Length + 1);
var length = context.Request.Path.Length - extension.Length;
context.Request.Url.Path = context.Request.Url.Path.Substring(0, length);
}

Expand Down