Added support for the AbortRequest action
This commit is contained in:
parent
c0425c6253
commit
7948a76f74
|
|
@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Rewrite.Logging
|
||||||
private static readonly Action<ILogger, Exception> _redirectedToHttps;
|
private static readonly Action<ILogger, Exception> _redirectedToHttps;
|
||||||
private static readonly Action<ILogger, string, Exception> _redirectSummary;
|
private static readonly Action<ILogger, string, Exception> _redirectSummary;
|
||||||
private static readonly Action<ILogger, string, Exception> _rewriteSummary;
|
private static readonly Action<ILogger, string, Exception> _rewriteSummary;
|
||||||
|
private static readonly Action<ILogger, string, Exception> _abortedRequest;
|
||||||
|
|
||||||
static RewriteMiddlewareLoggingExtensions()
|
static RewriteMiddlewareLoggingExtensions()
|
||||||
{
|
{
|
||||||
|
|
@ -70,6 +71,11 @@ namespace Microsoft.AspNetCore.Rewrite.Logging
|
||||||
LogLevel.Information,
|
LogLevel.Information,
|
||||||
10,
|
10,
|
||||||
"Request was rewritten to {rewrittenUrl}");
|
"Request was rewritten to {rewrittenUrl}");
|
||||||
|
|
||||||
|
_abortedRequest = LoggerMessage.Define<string>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
11,
|
||||||
|
"Request to {requestedUrl} was aborted");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RewriteMiddlewareRequestContinueResults(this ILogger logger, string currentUrl)
|
public static void RewriteMiddlewareRequestContinueResults(this ILogger logger, string currentUrl)
|
||||||
|
|
@ -121,5 +127,10 @@ namespace Microsoft.AspNetCore.Rewrite.Logging
|
||||||
{
|
{
|
||||||
_rewriteSummary(logger, rewrittenUrl, null);
|
_rewriteSummary(logger, rewrittenUrl, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AbortedRequest(this ILogger logger, string requestedUrl)
|
||||||
|
{
|
||||||
|
_abortedRequest(logger, requestedUrl, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
|
||||||
_action = new RedirectAction(statusCode, url, appendQueryString);
|
_action = new RedirectAction(statusCode, url, appendQueryString);
|
||||||
break;
|
break;
|
||||||
case ActionType.AbortRequest:
|
case ActionType.AbortRequest:
|
||||||
throw new NotImplementedException("Abort Requests are not implemented");
|
_action = new AbortAction();
|
||||||
|
break;
|
||||||
case ActionType.CustomResponse:
|
case ActionType.CustomResponse:
|
||||||
throw new NotImplementedException("Custom Responses are not implemented");
|
throw new NotImplementedException("Custom Responses are not implemented");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Rewrite.Logging;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
|
||||||
|
{
|
||||||
|
public class AbortAction : UrlAction
|
||||||
|
{
|
||||||
|
public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
|
||||||
|
{
|
||||||
|
context.HttpContext.Abort();
|
||||||
|
context.Result = RuleResult.EndResponse;
|
||||||
|
context.Logger?.AbortedRequest(context.HttpContext.Request.Path + context.HttpContext.Request.QueryString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
|
||||||
bool queryStringDelete,
|
bool queryStringDelete,
|
||||||
bool escapeBackReferences)
|
bool escapeBackReferences)
|
||||||
{
|
{
|
||||||
// For the replacement, we must have at least
|
// For the replacement, we must have at least
|
||||||
// one segment (cannot have an empty replacement)
|
// one segment (cannot have an empty replacement)
|
||||||
Result = result;
|
Result = result;
|
||||||
Url = pattern;
|
Url = pattern;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlActions
|
||||||
|
{
|
||||||
|
public class AbortActionTests
|
||||||
|
{
|
||||||
|
public void AbortAction_VerifyEndResponseResult()
|
||||||
|
{
|
||||||
|
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
||||||
|
var action = new AbortAction();
|
||||||
|
|
||||||
|
action.ApplyAction(context, null, null);
|
||||||
|
|
||||||
|
Assert.Equal(RuleResult.EndResponse, context.Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue