diff options
Diffstat (limited to 'src/Http/Http.Results/src/CreatedResult.cs')
-rw-r--r-- | src/Http/Http.Results/src/CreatedResult.cs | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/src/Http/Http.Results/src/CreatedResult.cs b/src/Http/Http.Results/src/CreatedResult.cs index b5b2d04bbf..6979c2160b 100644 --- a/src/Http/Http.Results/src/CreatedResult.cs +++ b/src/Http/Http.Results/src/CreatedResult.cs @@ -3,55 +3,54 @@ using System; -namespace Microsoft.AspNetCore.Http.Result +namespace Microsoft.AspNetCore.Http.Result; + +internal sealed class CreatedResult : ObjectResult { - internal sealed class CreatedResult : ObjectResult + /// <summary> + /// Initializes a new instance of the <see cref="CreatedResult"/> class with the values + /// provided. + /// </summary> + /// <param name="location">The location at which the content has been created.</param> + /// <param name="value">The value to format in the entity body.</param> + public CreatedResult(string location, object? value) + : base(value, StatusCodes.Status201Created) + { + Location = location; + } + + /// <summary> + /// Initializes a new instance of the <see cref="CreatedResult"/> class with the values + /// provided. + /// </summary> + /// <param name="location">The location at which the content has been created.</param> + /// <param name="value">The value to format in the entity body.</param> + public CreatedResult(Uri location, object? value) + : base(value, StatusCodes.Status201Created) { - /// <summary> - /// Initializes a new instance of the <see cref="CreatedResult"/> class with the values - /// provided. - /// </summary> - /// <param name="location">The location at which the content has been created.</param> - /// <param name="value">The value to format in the entity body.</param> - public CreatedResult(string location, object? value) - : base(value, StatusCodes.Status201Created) + if (location == null) { - Location = location; + throw new ArgumentNullException(nameof(location)); } - /// <summary> - /// Initializes a new instance of the <see cref="CreatedResult"/> class with the values - /// provided. - /// </summary> - /// <param name="location">The location at which the content has been created.</param> - /// <param name="value">The value to format in the entity body.</param> - public CreatedResult(Uri location, object? value) - : base(value, StatusCodes.Status201Created) + if (location.IsAbsoluteUri) { - if (location == null) - { - throw new ArgumentNullException(nameof(location)); - } - - if (location.IsAbsoluteUri) - { - Location = location.AbsoluteUri; - } - else - { - Location = location.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); - } + Location = location.AbsoluteUri; } - - /// <summary> - /// Gets or sets the location at which the content has been created. - /// </summary> - public string Location { get; init; } - - /// <inheritdoc /> - protected override void ConfigureResponseHeaders(HttpContext context) + else { - context.Response.Headers.Location = Location; + Location = location.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); } } + + /// <summary> + /// Gets or sets the location at which the content has been created. + /// </summary> + public string Location { get; init; } + + /// <inheritdoc /> + protected override void ConfigureResponseHeaders(HttpContext context) + { + context.Response.Headers.Location = Location; + } } |