Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Http/Wolverine.Http.Tests/posting_json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
5 changes: 5 additions & 0 deletions src/Http/Wolverine.Http/HttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILogger<T>>();
Expand Down
Loading