From 242b2ba753deefe70fd0ea98e9882a8048b36afb Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Fri, 14 Jul 2023 10:04:00 -0500 Subject: [PATCH] Test proving that an HTTP handler should be able to infer an EmptyResponse if all the return values are IWolverineReturnType Closes GH-473 --- src/Http/Wolverine.Http/HttpChain.cs | 2 ++ src/Http/Wolverine.Http/Resources/EmptyBody204Policy.cs | 1 + src/Http/WolverineWebApi/Samples/TodoController.cs | 2 +- src/Wolverine/ISendMyself.cs | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Http/Wolverine.Http/HttpChain.cs b/src/Http/Wolverine.Http/HttpChain.cs index f7670ce54..3be9245e7 100644 --- a/src/Http/Wolverine.Http/HttpChain.cs +++ b/src/Http/Wolverine.Http/HttpChain.cs @@ -103,6 +103,8 @@ private bool tryFindResourceType(MethodCall method, out Type resourceType) { return false; } + + resourceType = method.Creates.First().VariableType; return IsValidResponseType(resourceType); diff --git a/src/Http/Wolverine.Http/Resources/EmptyBody204Policy.cs b/src/Http/Wolverine.Http/Resources/EmptyBody204Policy.cs index f4f00ecf5..67a87de1f 100644 --- a/src/Http/Wolverine.Http/Resources/EmptyBody204Policy.cs +++ b/src/Http/Wolverine.Http/Resources/EmptyBody204Policy.cs @@ -12,6 +12,7 @@ public bool TryApply(HttpChain chain) if (chain.ResourceType == null || chain.ResourceType == typeof(void)) { chain.Postprocessors.Insert(0, new WriteEmptyBodyStatusCode()); + chain.Metadata.Produces(204); return true; } diff --git a/src/Http/WolverineWebApi/Samples/TodoController.cs b/src/Http/WolverineWebApi/Samples/TodoController.cs index db6842fb3..80fc1f024 100644 --- a/src/Http/WolverineWebApi/Samples/TodoController.cs +++ b/src/Http/WolverineWebApi/Samples/TodoController.cs @@ -127,7 +127,7 @@ public static class UpdateEndpoint public static Task LoadAsync(int id, IDocumentSession session) => session.LoadAsync(id); - [WolverinePut("/todos/{id:int}"), EmptyResponse] + [WolverinePut("/todos/{id:int}")] public static StoreDoc Put(int id, UpdateRequest request, [Required] Todo? todo) { todo.Name = request.Name; diff --git a/src/Wolverine/ISendMyself.cs b/src/Wolverine/ISendMyself.cs index 2658db54d..05bd09c5d 100644 --- a/src/Wolverine/ISendMyself.cs +++ b/src/Wolverine/ISendMyself.cs @@ -1,10 +1,12 @@ +using Wolverine.Configuration; + namespace Wolverine; /// /// Interface for cascading messages that require some customization of how /// the resulting inner message is sent out /// -public interface ISendMyself +public interface ISendMyself : IWolverineReturnType { ValueTask ApplyAsync(IMessageContext context); }