Skip to content

Commit

Permalink
Merge pull request #32 from LykkeCity/NoContentFilter
Browse files Browse the repository at this point in the history
Fixed NoContentFilter to properly process OkObjectResult
  • Loading branch information
Sergey Nesterov committed May 6, 2019
2 parents 34b887b + 92e024e commit be4cdd2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Lykke.Common.ApiLibrary/Filters/NoContentFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using JetBrains.Annotations;
using Lykke.Common.Log;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Lykke.Common.ApiLibrary.Filters
Expand All @@ -28,10 +29,14 @@ public void OnResultExecuted(ResultExecutedContext context)
var response = context.HttpContext.Response;
if (response.StatusCode == StatusCodes.Status200OK && (response.ContentLength ?? 0) == 0)
{
if (response.HasStarted)
_log.Warning($"Couldn't set NoContent into response to {context.HttpContext.Request.Method} {context.HttpContext.Request.Path}");
else
response.StatusCode = StatusCodes.Status204NoContent;
var okResult = context.Result as OkObjectResult;
if (okResult?.Value == null)
{
if (response.HasStarted)
_log.Warning($"Couldn't set NoContent into response to {context.HttpContext.Request.Method} {context.HttpContext.Request.Path}");
else
response.StatusCode = StatusCodes.Status204NoContent;
}
}
}
}
Expand Down

0 comments on commit be4cdd2

Please sign in to comment.