Preserve redirect query string (#237)
This commit is contained in:
parent
aae6b44900
commit
65c78d12b5
|
|
@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.Headers[HeaderNames.Location] = pathBase + newPath;
|
response.Headers[HeaderNames.Location] = pathBase + newPath + context.HttpContext.Request.QueryString;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Logger?.RedirectedSummary(newPath);
|
context.Logger?.RedirectedSummary(newPath);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,22 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.CodeRules
|
||||||
Assert.Equal("http://example.com/foo", response.Headers.Location.OriginalString);
|
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]
|
[Theory]
|
||||||
[InlineData(StatusCodes.Status301MovedPermanently)]
|
[InlineData(StatusCodes.Status301MovedPermanently)]
|
||||||
[InlineData(StatusCodes.Status302Found)]
|
[InlineData(StatusCodes.Status302Found)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue