diff --git a/src/Http/Wolverine.Http.Tests/posting_json.cs b/src/Http/Wolverine.Http.Tests/posting_json.cs index 69eb82014..a487d3cdb 100644 --- a/src/Http/Wolverine.Http.Tests/posting_json.cs +++ b/src/Http/Wolverine.Http.Tests/posting_json.cs @@ -112,4 +112,22 @@ public async Task post_json_but_accept_text_get_406() x.StatusCodeShouldBe(406); }); } + + [Fact] + public async Task reading_json_from_canceled_request_gets_204() + { + var cts = new CancellationTokenSource(); + cts.Cancel(); + + var response = await Scenario(x => + { + x.ConfigureHttpContext(ctx => + { + ctx.Request.HttpContext.RequestAborted = cts.Token; + }); + x.Post.Json(new Question { One = 3, Two = 4 }).ToUrl("/question"); + x.WithRequestHeader("accept", "application/json"); + x.StatusCodeShouldBe(204); + }); + } } \ No newline at end of file diff --git a/src/Http/Wolverine.Http/HttpHandler.cs b/src/Http/Wolverine.Http/HttpHandler.cs index 1cc96f2ba..257bf85e7 100644 --- a/src/Http/Wolverine.Http/HttpHandler.cs +++ b/src/Http/Wolverine.Http/HttpHandler.cs @@ -156,6 +156,11 @@ private static bool isRequestJson(HttpContext context) return (body, HandlerContinuation.Continue); } + catch (OperationCanceledException) + { + context.Response.StatusCode = 204; + return (default, HandlerContinuation.Stop); + } catch (Exception e) { var logger = context.RequestServices.GetService>();