Save condition backcollection between runs (#10776)
This commit is contained in:
parent
3bb092bdab
commit
45b0d0d0de
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -39,6 +39,8 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
||||||
context.Logger?.ModRewriteNotMatchedRule();
|
context.Logger?.ModRewriteNotMatchedRule();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
condBackReferences = condResult.BackReferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, we know our rule passed, first apply pre conditions,
|
// At this point, we know our rule passed, first apply pre conditions,
|
||||||
|
|
@ -51,4 +53,4 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -308,5 +308,25 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite
|
||||||
|
|
||||||
Assert.Equal("/foo", response.Headers.Location.OriginalString);
|
Assert.Equal("/foo", response.Headers.Location.OriginalString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CapturedVariablesInConditionsArePreservedToRewriteRule()
|
||||||
|
{
|
||||||
|
var options = new RewriteOptions().AddApacheModRewrite(new StringReader(@"RewriteCond %{REQUEST_URI} /home
|
||||||
|
RewriteCond %{QUERY_STRING} report_id=(.+)
|
||||||
|
RewriteRule (.*) http://localhost:80/home/report/%1 [R=301,L,QSD]"));
|
||||||
|
var builder = new WebHostBuilder().Configure(app =>
|
||||||
|
{
|
||||||
|
app.UseRewriter(options);
|
||||||
|
app.Run(context => context.Response.WriteAsync(
|
||||||
|
context.Request.Path +
|
||||||
|
context.Request.QueryString));
|
||||||
|
});
|
||||||
|
|
||||||
|
var server = new TestServer(builder) { BaseAddress = new Uri("http://localhost:5000/foo") };
|
||||||
|
var response = await server.CreateClient().GetAsync("/home?report_id=123");
|
||||||
|
|
||||||
|
Assert.Equal("http://localhost:80/home/report/123", response.Headers.Location.OriginalString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue