Preserve redirect query string (#237)

This commit is contained in:
Mikael Mengistu 2017-05-30 20:42:28 -04:00 коммит произвёл GitHub
Родитель aae6b44900
Коммит 65c78d12b5
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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)]