The response status code can be set in requests handlers and it'll be honored by the composition pipeline. To set a custom response status code the following snippet can be used:
public class SampleHandlerWithCustomStatusCode : ICompositionRequestsHandler
{
[HttpGet("/sample/{id}")]
public Task Handle(HttpRequest request)
{
var response = request.HttpContext.Response;
response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.CompletedTask;
}
}
Note
Requests handlers are executed in parallel in a non-deterministic way, setting the response code in more than one handler can have unpredictable effects.