dotnet / aspnetcore Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CreatedResult
should accept null location
#39454
Comments
[HttpPost]
public ActionResult Create()
{
return new StatusCodeResult(StatusCodes.Status201Created);
} [HttpPost]
public ActionResult Create()
{
return StatusCode(StatusCodes.Status201Created);
} |
Since your examples pass Now, I have wished for an overload of |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Strawman API proposal: namespace Microsoft.AspNetCore.Mvc
{
public class CreatedResult : ObjectResult
{
+ public CreatedResult()
- public CreatedResult(string location, object? value)
+ public CreatedResult(string? location, object? value)
- public CreatedResult(Uri location, object? value)
+ public CreatedResult(Uri? location, object? value)
}
public abstract class ControllerBase
{
+ public virtual CreatedResult Created()
- public virtual CreatedResult Created(string uri, [ActionResultObjectValue] object? value)
+ public virtual CreatedResult Created(string? uri, [ActionResultObjectValue] object? value)
- public virtual CreatedResult Created(Uri uri, [ActionResultObjectValue] object? value)
+ public virtual CreatedResult Created(Uri? uri, [ActionResultObjectValue] object? value)
}
}
namespace Microsoft.AspNetCore.Http
{
public static class Results
{
+ public static IResult Created()
- public static IResult Created(string uri, object? value)
+ public static IResult Created(string uri?, object? value)
- public static IResult Created(Uri uri, object? value)
+ public static IResult Created(string uri?, object? value)
}
} I'm not super convinced that making the location/uri parameters nullable is a huge win since you'd need either |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Is there an existing issue for this?
Describe the bug
RFC7231 suggests that the
Location
header is optional for201
Created response.However, currently the constructors of
CreateResult
throws ifnull
is passed tolocation
, andControllerBase.Created()
throws ifnull
is passed tourl
.Expected Behavior
A response of
201
Created withoutLocation
header is created.Steps To Reproduce
Exceptions (if any)
.NET Version
6.0.101
Anything else?
No response
The text was updated successfully, but these errors were encountered: