Created
February 10, 2017 23:00
-
-
Save davidpeden3/1ef73ea305fe262da5aab60150219131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override Task ApplyActionAsync(RewriteContext context, BackReferenceCollection ruleBackReferences, BackReferenceCollection conditionBackReferences) | |
{ | |
var response = context.HttpContext.Response; | |
response.StatusCode = StatusCode; | |
if (!string.IsNullOrEmpty(StatusReason)) | |
{ | |
context.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = StatusReason; | |
} | |
context.Result = RuleResult.EndResponse; | |
context.Logger?.CustomResponse(context.HttpContext.Request.GetEncodedUrl()); | |
if (!string.IsNullOrEmpty(StatusDescription)) | |
{ | |
var content = Encoding.UTF8.GetBytes(StatusDescription); | |
response.ContentLength = content.Length; | |
response.ContentType = "text/plain; charset=utf-8"; | |
response.Body.Write(content, 0, content.Length); | |
} | |
return TaskCache.CompletedTask; | |
} |
regarding StatusDescription
, i'm not following you. it may or may not be set. are you suggesting making additional constructor overloads to account for the combination of possible parameters? i can add:
public CustomResponseAction(int statusCode, string statusReason, string statusDescription)
but can't account for the other two individually since they share the same signature. that's why i initially went with settable properties. if it's valid to say that you can't/won't have a StatusDescription
without also having a StatusReason
, then that's obviously doable.
what do you suggest?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, since the StatusDescription is constant, you could
Encoding.UTF8.GetBytes(StatusDescription);
move to the constructor