Preserve redirect query string (#237)

This commit is contained in:
Mikael Mengistu 2017-05-30 20:42:28 -04:00 committed by GitHub
parent aae6b44900
commit 65c78d12b5
2 changed files with 17 additions and 1 deletions

View File

@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
}
else
{
response.Headers[HeaderNames.Location] = pathBase + newPath;
response.Headers[HeaderNames.Location] = pathBase + newPath + context.HttpContext.Request.QueryString;
}
context.Logger?.RedirectedSummary(newPath);

View File

@ -51,6 +51,22 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.CodeRules
Assert.Equal("http://example.com/foo", response.Headers.Location.OriginalString);
}
[Fact]
public async Task CheckRedirectPathWithQueryString()
{
var options = new RewriteOptions().AddRedirect("(.*)","http://example.com/$1", statusCode: StatusCodes.Status301MovedPermanently);
var builder = new WebHostBuilder()
.Configure(app =>
{
app.UseRewriter(options);
});
var server = new TestServer(builder);
var response = await server.CreateClient().GetAsync("foo?bar=1");
Assert.Equal("http://example.com/foo?bar=1", response.Headers.Location.OriginalString);
}
[Theory]
[InlineData(StatusCodes.Status301MovedPermanently)]
[InlineData(StatusCodes.Status302Found)]