From ad76c8b34ea4dba75b9980a2b5290cb1537c9ef2 Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Wed, 23 Mar 2022 13:18:44 -0700 Subject: [PATCH 1/6] Adding public constructors --- .../src/AcceptedAtRouteHttpResult.cs | 24 ++--- .../Http.Results/src/AcceptedHttpResult.cs | 24 ++++- .../src/BadRequestObjectHttpResult.cs | 9 +- .../Http.Results/src/ChallengeHttpResult.cs | 36 ++----- .../src/ConflictObjectHttpResult.cs | 9 +- .../Http.Results/src/ContentHttpResult.cs | 24 +++-- .../src/CreatedAtRouteHttpResult.cs | 24 ++--- .../Http.Results/src/CreatedHttpResult.cs | 28 ++++- .../Http.Results/src/FileContentHttpResult.cs | 71 ++++-------- .../Http.Results/src/FileStreamHttpResult.cs | 71 ++++-------- src/Http/Http.Results/src/ForbidHttpResult.cs | 36 ++----- src/Http/Http.Results/src/JsonHttpResult.cs | 47 ++------ .../Http.Results/src/NoContentHttpResult.cs | 7 +- .../src/NotFoundObjectHttpResult.cs | 9 +- src/Http/Http.Results/src/ObjectHttpResult.cs | 40 +++---- .../Http.Results/src/OkObjectHttpResult.cs | 10 +- .../src/PhysicalFileHttpResult.cs | 76 +++++-------- .../Http.Results/src/ProblemHttpResult.cs | 39 ++++++- .../Http.Results/src/PublicAPI.Unshipped.txt | 101 ++++++++++++++++++ .../Http.Results/src/PushStreamHttpResult.cs | 62 +++-------- .../Http.Results/src/RedirectHttpResult.cs | 53 +++------ .../src/RedirectToRouteHttpResult.cs | 99 +++-------------- src/Http/Http.Results/src/Results.cs | 43 +++----- src/Http/Http.Results/src/SignInHttpResult.cs | 25 ++--- .../Http.Results/src/SignOutHttpResult.cs | 56 +++------- .../Http.Results/src/StatusCodeHttpResult.cs | 2 +- .../src/UnauthorizedHttpResult.cs | 7 +- .../UnprocessableEntityObjectHttpResult.cs | 7 +- .../Http.Results/src/VirtualFileHttpResult.cs | 90 ++++++---------- .../test/AcceptedAtRouteResultTests.cs | 2 +- .../test/CreatedAtRouteResultTests.cs | 2 +- .../test/LocalRedirectResultTest.cs | 15 +-- .../Http.Results/test/NoContentResultTests.cs | 4 +- .../test/RedirectToRouteResultTest.cs | 2 +- .../test/UnauthorizedResultTests.cs | 4 +- 35 files changed, 502 insertions(+), 656 deletions(-) diff --git a/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs b/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs index 0e45e84164ce..b422cbffb8a7 100644 --- a/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs +++ b/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs @@ -15,17 +15,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class AcceptedAtRouteHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The route data to use for generating the URL. - /// The value to format in the entity body. - internal AcceptedAtRouteHttpResult(object? routeValues, object? value) - : this(routeName: null, routeValues: routeValues, value: value) - { - } - /// /// Initializes a new instance of the class with the values /// provided. @@ -33,10 +22,10 @@ internal AcceptedAtRouteHttpResult(object? routeValues, object? value) /// The name of the route to use for generating the URL. /// The route data to use for generating the URL. /// The value to format in the entity body. - internal AcceptedAtRouteHttpResult( - string? routeName, - object? routeValues, - object? value) + public AcceptedAtRouteHttpResult( + string? routeName = null, + object? routeValues = null, + object? value = null) { Value = value; RouteName = routeName; @@ -44,6 +33,11 @@ internal AcceptedAtRouteHttpResult( HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a , and . + /// + public static AcceptedAtRouteHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/AcceptedHttpResult.cs b/src/Http/Http.Results/src/AcceptedHttpResult.cs index d0b6026e0c56..0608215cdabd 100644 --- a/src/Http/Http.Results/src/AcceptedHttpResult.cs +++ b/src/Http/Http.Results/src/AcceptedHttpResult.cs @@ -14,26 +14,46 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class AcceptedHttpResult : IResult { + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The location at which the status of requested content can be monitored. + public AcceptedHttpResult(string? location) + : this(location, null) + { + } + /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - internal AcceptedHttpResult(string? location, object? value) + public AcceptedHttpResult(string? location, object? value) { Value = value; Location = location; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The location at which the status of requested content can be monitored. + public AcceptedHttpResult(Uri locationUri) + : this(locationUri, null) + { + } + /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - internal AcceptedHttpResult(Uri locationUri, object? value) + public AcceptedHttpResult(Uri locationUri, object? value) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs index dc9ad6e4fb2f..8f1436074ec3 100644 --- a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs +++ b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs @@ -17,16 +17,21 @@ public sealed class BadRequestObjectHttpResult : IResult /// provided. /// /// The error content to format in the entity body. - internal BadRequestObjectHttpResult(object? error) + public BadRequestObjectHttpResult(object? error = null) { Value = error; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a . + /// + public static BadRequestObjectHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// - public object? Value { get; internal init; } + public object? Value { get; } /// /// Gets the HTTP status code. diff --git a/src/Http/Http.Results/src/ChallengeHttpResult.cs b/src/Http/Http.Results/src/ChallengeHttpResult.cs index cff6c06937dd..f22600ee26f4 100644 --- a/src/Http/Http.Results/src/ChallengeHttpResult.cs +++ b/src/Http/Http.Results/src/ChallengeHttpResult.cs @@ -14,30 +14,10 @@ namespace Microsoft.AspNetCore.Http; public sealed partial class ChallengeHttpResult : IResult { /// - /// Initializes a new instance of . + /// Initializes a new instance of with the default sign out scheme. /// - internal ChallengeHttpResult() - : this(Array.Empty()) - { - } - - /// - /// Initializes a new instance of with the - /// specified authentication scheme. - /// - /// The authentication scheme to challenge. - internal ChallengeHttpResult(string authenticationScheme) - : this(new[] { authenticationScheme }) - { - } - - /// - /// Initializes a new instance of with the - /// specified authentication schemes. - /// - /// The authentication schemes to challenge. - internal ChallengeHttpResult(IList authenticationSchemes) - : this(authenticationSchemes, properties: null) + public ChallengeHttpResult() + : this(authenticationSchemes: Array.Empty(), properties: null) { } @@ -47,7 +27,7 @@ internal ChallengeHttpResult(IList authenticationSchemes) /// /// used to perform the authentication /// challenge. - internal ChallengeHttpResult(AuthenticationProperties? properties) + public ChallengeHttpResult(AuthenticationProperties? properties) : this(Array.Empty(), properties) { } @@ -59,7 +39,7 @@ internal ChallengeHttpResult(AuthenticationProperties? properties) /// The authentication schemes to challenge. /// used to perform the authentication /// challenge. - internal ChallengeHttpResult(string authenticationScheme, AuthenticationProperties? properties) + public ChallengeHttpResult(string authenticationScheme, AuthenticationProperties? properties) : this(new[] { authenticationScheme }, properties) { } @@ -71,7 +51,7 @@ internal ChallengeHttpResult(string authenticationScheme, AuthenticationProperti /// The authentication scheme to challenge. /// used to perform the authentication /// challenge. - internal ChallengeHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + public ChallengeHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) { AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; @@ -80,12 +60,12 @@ internal ChallengeHttpResult(IList authenticationSchemes, Authentication /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; internal init; } = Array.Empty(); + public IReadOnlyList AuthenticationSchemes { get; init; } /// /// Gets the used to perform the sign-out operation. /// - public AuthenticationProperties? Properties { get; internal init; } + public AuthenticationProperties? Properties { get; } /// public async Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs index 782775395bfc..f7145ad75297 100644 --- a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs +++ b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs @@ -17,16 +17,21 @@ public sealed class ConflictObjectHttpResult : IResult /// provided. /// /// The error content to format in the entity body. - internal ConflictObjectHttpResult(object? error) + public ConflictObjectHttpResult(object? error = null) { Value = error; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a . + /// + public static ConflictObjectHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// - public object? Value { get; internal init; } + public object? Value { get; } /// /// Gets the HTTP status code. diff --git a/src/Http/Http.Results/src/ContentHttpResult.cs b/src/Http/Http.Results/src/ContentHttpResult.cs index a50675408e2d..f14c2009fc7f 100644 --- a/src/Http/Http.Results/src/ContentHttpResult.cs +++ b/src/Http/Http.Results/src/ContentHttpResult.cs @@ -13,42 +13,46 @@ namespace Microsoft.AspNetCore.Http; public sealed partial class ContentHttpResult : IResult { /// - /// Initializes a new instance of the class with the values. + /// Initializes a new instance of the class + /// + public ContentHttpResult() + { + } + + /// + /// Initializes a new instance of the class with the values /// /// The value to format in the entity body. - /// The Content-Type header for the response - internal ContentHttpResult(string? content, string? contentType) - : this(content, contentType, statusCode: null) + public ContentHttpResult(string content) { + Content = content; } /// /// Initializes a new instance of the class with the values /// /// The value to format in the entity body. - /// The HTTP status code of the response. /// The Content-Type header for the response - internal ContentHttpResult(string? content, string? contentType, int? statusCode) + public ContentHttpResult(string content, string contentType) { Content = content; - StatusCode = statusCode; ContentType = contentType; } /// /// Gets or set the content representing the body of the response. /// - public string? Content { get; internal init; } + public string? Content { get; init;} /// /// Gets or sets the Content-Type header for the response. /// - public string? ContentType { get; internal init; } + public string? ContentType { get; init; } /// /// Gets the HTTP status code. /// - public int? StatusCode { get; internal init; } + public int? StatusCode { get; init; } /// /// Writes the content to the HTTP response. diff --git a/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs b/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs index f59593be8505..f89c59273720 100644 --- a/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs +++ b/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs @@ -14,17 +14,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class CreatedAtRouteHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The route data to use for generating the URL. - /// The value to format in the entity body. - internal CreatedAtRouteHttpResult(object? routeValues, object? value) - : this(routeName: null, routeValues: routeValues, value: value) - { - } - /// /// Initializes a new instance of the class with the values /// provided. @@ -32,10 +21,10 @@ internal CreatedAtRouteHttpResult(object? routeValues, object? value) /// The name of the route to use for generating the URL. /// The route data to use for generating the URL. /// The value to format in the entity body. - internal CreatedAtRouteHttpResult( - string? routeName, - object? routeValues, - object? value) + public CreatedAtRouteHttpResult( + string? routeName = null, + object? routeValues = null, + object? value = null) { Value = value; RouteName = routeName; @@ -43,6 +32,11 @@ internal CreatedAtRouteHttpResult( HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a , and . + /// + public static CreatedAtRouteHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/CreatedHttpResult.cs b/src/Http/Http.Results/src/CreatedHttpResult.cs index 4106cacd7fec..62e12334ad51 100644 --- a/src/Http/Http.Results/src/CreatedHttpResult.cs +++ b/src/Http/Http.Results/src/CreatedHttpResult.cs @@ -16,9 +16,19 @@ public sealed class CreatedHttpResult : IResult /// Initializes a new instance of the class with the values /// provided. /// - /// The location at which the content has been created. + /// The location at which the status of requested content can be monitored. + public CreatedHttpResult(string? location) + : this(location, null) + { + } + + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - internal CreatedHttpResult(string location, object? value) + public CreatedHttpResult(string? location, object? value) { Value = value; Location = location; @@ -29,9 +39,19 @@ internal CreatedHttpResult(string location, object? value) /// Initializes a new instance of the class with the values /// provided. /// - /// The location at which the content has been created. + /// The location at which the status of requested content can be monitored. + public CreatedHttpResult(Uri locationUri) + : this(locationUri, null) + { + } + + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - internal CreatedHttpResult(Uri locationUri, object? value) + public CreatedHttpResult(Uri locationUri, object? value) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/FileContentHttpResult.cs b/src/Http/Http.Results/src/FileContentHttpResult.cs index 56cd17d13944..426a53a642ae 100644 --- a/src/Http/Http.Results/src/FileContentHttpResult.cs +++ b/src/Http/Http.Results/src/FileContentHttpResult.cs @@ -15,30 +15,11 @@ namespace Microsoft.AspNetCore.Http; public sealed partial class FileContentHttpResult : IResult { /// - /// Creates a new instance with - /// the provided and the - /// provided . - /// - /// The bytes that represent the file contents. - /// The Content-Type of the file. - internal FileContentHttpResult(ReadOnlyMemory fileContents, string? contentType) - : this(fileContents, contentType, fileDownloadName: null) - { - } - - /// - /// Creates a new instance with - /// the provided , the provided - /// and the provided . + /// Creates a new instance with the provided values. /// /// The bytes that represent the file contents. - /// The Content-Type header of the response. - /// The suggested file name. - internal FileContentHttpResult( - ReadOnlyMemory fileContents, - string? contentType, - string? fileDownloadName) - : this(fileContents, contentType, fileDownloadName, enableRangeProcessing: false) + public FileContentHttpResult(ReadOnlyMemory fileContents) + : this(fileContents, contentType: null) { } @@ -46,62 +27,48 @@ internal FileContentHttpResult( /// Creates a new instance with the provided values. /// /// The bytes that represent the file contents. - /// The Content-Type of the file. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. - internal FileContentHttpResult( - ReadOnlyMemory fileContents, - string? contentType, - string? fileDownloadName, - bool enableRangeProcessing, - DateTimeOffset? lastModified = null, - EntityTagHeaderValue? entityTag = null) + /// The Content-Type header of the response. + public FileContentHttpResult(ReadOnlyMemory fileContents, string? contentType) { FileContents = fileContents; FileLength = fileContents.Length; ContentType = contentType ?? "application/octet-stream"; - FileDownloadName = fileDownloadName; - EnableRangeProcessing = enableRangeProcessing; - LastModified = lastModified; - EntityTag = entityTag; } /// - /// Gets the Content-Type header for the response. + /// Gets the file contents. /// - public string ContentType { get; internal set; } + public ReadOnlyMemory FileContents { get; } /// - /// Gets the file name that will be used in the Content-Disposition header of the response. + /// Gets the file length information . /// - public string? FileDownloadName { get; internal set; } + public long? FileLength { get; } /// - /// Gets the last modified information associated with the file result. + /// Gets the Content-Type header for the response. /// - public DateTimeOffset? LastModified { get; internal set; } + public string ContentType { get; init; } /// - /// Gets the etag associated with the file result. + /// Gets the value that enables range processing for the file result. /// - public EntityTagHeaderValue? EntityTag { get; internal init; } + public bool EnableRangeProcessing { get; init; } /// - /// Gets the value that enables range processing for the file result. + /// Gets the etag associated with the file result. /// - public bool EnableRangeProcessing { get; internal init; } + public EntityTagHeaderValue? EntityTag { get; init; } /// - /// Gets or sets the file length information . + /// Gets the file name that will be used in the Content-Disposition header of the response. /// - public long? FileLength { get; internal set; } + public string? FileDownloadName { get; init; } /// - /// Gets or sets the file contents. + /// Gets the last modified information associated with the file result. /// - public ReadOnlyMemory FileContents { get; internal init; } + public DateTimeOffset? LastModified { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/FileStreamHttpResult.cs b/src/Http/Http.Results/src/FileStreamHttpResult.cs index 4a2273c535f0..be185c97b951 100644 --- a/src/Http/Http.Results/src/FileStreamHttpResult.cs +++ b/src/Http/Http.Results/src/FileStreamHttpResult.cs @@ -15,30 +15,11 @@ namespace Microsoft.AspNetCore.Http; public sealed class FileStreamHttpResult : IResult { /// - /// Creates a new instance with - /// the provided and the - /// provided . + /// Creates a new instance with the provided values. /// /// The stream with the file. - /// The Content-Type of the file. - internal FileStreamHttpResult(Stream fileStream, string? contentType) - : this(fileStream, contentType, fileDownloadName: null) - { - } - - /// - /// Creates a new instance with - /// the provided , the provided - /// and the provided . - /// - /// The stream with the file. - /// The Content-Type header of the response. - /// The suggested file name. - internal FileStreamHttpResult( - Stream fileStream, - string? contentType, - string? fileDownloadName) - : this(fileStream, contentType, fileDownloadName, enableRangeProcessing: false) + public FileStreamHttpResult(Stream fileStream) + : this(fileStream, contentType: null) { } @@ -46,18 +27,8 @@ internal FileStreamHttpResult( /// Creates a new instance with the provided values. /// /// The stream with the file. - /// The Content-Type of the file. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. - internal FileStreamHttpResult( - Stream fileStream, - string? contentType, - string? fileDownloadName, - bool enableRangeProcessing, - DateTimeOffset? lastModified = null, - EntityTagHeaderValue? entityTag = null) + /// The Content-Type header of the response. + public FileStreamHttpResult(Stream fileStream, string? contentType) { if (fileStream == null) { @@ -71,46 +42,42 @@ internal FileStreamHttpResult( } ContentType = contentType ?? "application/octet-stream"; - FileDownloadName = fileDownloadName; - EnableRangeProcessing = enableRangeProcessing; - LastModified = lastModified; - EntityTag = entityTag; } /// - /// Gets the Content-Type header for the response. + /// Gets or sets the stream with the file that will be sent back as the response. /// - public string ContentType { get; internal set; } + public Stream FileStream { get; } /// - /// Gets the file name that will be used in the Content-Disposition header of the response. + /// Gets or sets the file length information . /// - public string? FileDownloadName { get; internal set; } + public long? FileLength { get; } /// - /// Gets the last modified information associated with the file result. + /// Gets the Content-Type header for the response. /// - public DateTimeOffset? LastModified { get; internal set; } + public string ContentType { get; init; } /// - /// Gets the etag associated with the file result. + /// Gets the value that enables range processing for the file result. /// - public EntityTagHeaderValue? EntityTag { get; internal init; } + public bool EnableRangeProcessing { get; init; } /// - /// Gets the value that enables range processing for the file result. + /// Gets the etag associated with the file result. /// - public bool EnableRangeProcessing { get; internal init; } + public EntityTagHeaderValue? EntityTag { get; init; } /// - /// Gets or sets the file length information . + /// Gets the file name that will be used in the Content-Disposition header of the response. /// - public long? FileLength { get; internal set; } + public string? FileDownloadName { get; init; } /// - /// Gets or sets the stream with the file that will be sent back as the response. + /// Gets the last modified information associated with the file result. /// - public Stream FileStream { get; } + public DateTimeOffset? LastModified { get; init; } /// public async Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/ForbidHttpResult.cs b/src/Http/Http.Results/src/ForbidHttpResult.cs index f9d8d9c27897..cdf4f888553b 100644 --- a/src/Http/Http.Results/src/ForbidHttpResult.cs +++ b/src/Http/Http.Results/src/ForbidHttpResult.cs @@ -14,30 +14,10 @@ namespace Microsoft.AspNetCore.Http; public sealed partial class ForbidHttpResult : IResult { /// - /// Initializes a new instance of . + /// Initializes a new instance of with the default sign out scheme. /// - internal ForbidHttpResult() - : this(Array.Empty()) - { - } - - /// - /// Initializes a new instance of with the - /// specified authentication scheme. - /// - /// The authentication scheme to challenge. - internal ForbidHttpResult(string authenticationScheme) - : this(new[] { authenticationScheme }) - { - } - - /// - /// Initializes a new instance of with the - /// specified authentication schemes. - /// - /// The authentication schemes to challenge. - internal ForbidHttpResult(IList authenticationSchemes) - : this(authenticationSchemes, properties: null) + public ForbidHttpResult() + : this(authenticationSchemes: Array.Empty(), properties: null) { } @@ -47,7 +27,7 @@ internal ForbidHttpResult(IList authenticationSchemes) /// /// used to perform the authentication /// challenge. - internal ForbidHttpResult(AuthenticationProperties? properties) + public ForbidHttpResult(AuthenticationProperties? properties) : this(Array.Empty(), properties) { } @@ -59,7 +39,7 @@ internal ForbidHttpResult(AuthenticationProperties? properties) /// The authentication schemes to challenge. /// used to perform the authentication /// challenge. - internal ForbidHttpResult(string authenticationScheme, AuthenticationProperties? properties) + public ForbidHttpResult(string authenticationScheme, AuthenticationProperties? properties) : this(new[] { authenticationScheme }, properties) { } @@ -71,7 +51,7 @@ internal ForbidHttpResult(string authenticationScheme, AuthenticationProperties? /// The authentication scheme to challenge. /// used to perform the authentication /// challenge. - internal ForbidHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + public ForbidHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) { AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; @@ -80,12 +60,12 @@ internal ForbidHttpResult(IList authenticationSchemes, AuthenticationPro /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; internal init; } + public IReadOnlyList AuthenticationSchemes { get; init; } /// /// Gets the used to perform the authentication challenge. /// - public AuthenticationProperties? Properties { get; internal init; } + public AuthenticationProperties? Properties { get; } /// public async Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/JsonHttpResult.cs b/src/Http/Http.Results/src/JsonHttpResult.cs index 1e7800a32bdb..ee7de81576a7 100644 --- a/src/Http/Http.Results/src/JsonHttpResult.cs +++ b/src/Http/Http.Results/src/JsonHttpResult.cs @@ -16,9 +16,8 @@ public sealed class JsonHttpResult : IResult /// Initializes a new instance of the class with the values. /// /// The value to format in the entity body. - /// The serializer settings. - internal JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOptions) - : this(value, statusCode: null, contentType: null, jsonSerializerOptions: jsonSerializerOptions) + public JsonHttpResult(object? value) + : this(value, null) { } @@ -26,60 +25,34 @@ internal JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOpti /// Initializes a new instance of the class with the values. /// /// The value to format in the entity body. - /// The HTTP status code of the response. /// The serializer settings. - internal JsonHttpResult(object? value, int? statusCode, JsonSerializerOptions? jsonSerializerOptions) - : this(value, statusCode: statusCode, contentType: null, jsonSerializerOptions: jsonSerializerOptions) - { - } - - /// - /// Initializes a new instance of the class with the values. - /// - /// The value to format in the entity body. - /// The value for the Content-Type header - /// The serializer settings. - internal JsonHttpResult(object? value, string? contentType, JsonSerializerOptions? jsonSerializerOptions) - : this(value, statusCode: null, contentType: contentType, jsonSerializerOptions: jsonSerializerOptions) - { - - } - - /// - /// Initializes a new instance of the class with the values. - /// - /// The value to format in the entity body. - /// The HTTP status code of the response. - /// The serializer settings. - /// The value for the Content-Type header - internal JsonHttpResult(object? value, int? statusCode, string? contentType, JsonSerializerOptions? jsonSerializerOptions) + public JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOptions) { Value = value; - StatusCode = statusCode; JsonSerializerOptions = jsonSerializerOptions; - ContentType = contentType; + HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } /// - /// Gets or sets the serializer settings. + /// Gets the object result. /// - public JsonSerializerOptions? JsonSerializerOptions { get; internal init; } + public object? Value { get; } /// - /// Gets the object result. + /// Gets or sets the serializer settings. /// - public object? Value { get; } + public JsonSerializerOptions? JsonSerializerOptions { get; init; } /// /// Gets the value for the Content-Type header. /// - public string? ContentType { get; internal set; } + public string? ContentType { get; init; } /// /// Gets the HTTP status code. /// - public int? StatusCode { get; } + public int? StatusCode { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/NoContentHttpResult.cs b/src/Http/Http.Results/src/NoContentHttpResult.cs index 0339cc3f1f38..804b0bbbf572 100644 --- a/src/Http/Http.Results/src/NoContentHttpResult.cs +++ b/src/Http/Http.Results/src/NoContentHttpResult.cs @@ -15,10 +15,15 @@ public class NoContentHttpResult : IResult /// /// Initializes a new instance of the class. /// - internal NoContentHttpResult() + private NoContentHttpResult() { } + /// + /// Gets an instance of . + /// + public static NoContentHttpResult Instance { get; } = new(); + /// /// Gets the HTTP status code. /// diff --git a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs index 45220b7d0483..2667fe92f182 100644 --- a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs +++ b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs @@ -16,16 +16,21 @@ public sealed class NotFoundObjectHttpResult : IResult /// Initializes a new instance of the class with the values. /// /// The value to format in the entity body. - internal NotFoundObjectHttpResult(object? value) + public NotFoundObjectHttpResult(object? value = null) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a . + /// + public static NotFoundObjectHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// - public object? Value { get; internal init; } + public object? Value { get; } /// /// Gets the HTTP status code. diff --git a/src/Http/Http.Results/src/ObjectHttpResult.cs b/src/Http/Http.Results/src/ObjectHttpResult.cs index 252ab122a1da..e57965b02c6c 100644 --- a/src/Http/Http.Results/src/ObjectHttpResult.cs +++ b/src/Http/Http.Results/src/ObjectHttpResult.cs @@ -12,56 +12,50 @@ namespace Microsoft.AspNetCore.Http; /// internal sealed class ObjectHttpResult : IResult { - /// - /// Creates a new instance - /// with the provided . - /// - internal ObjectHttpResult(object? value) - : this(value, null) - { - } - /// /// Creates a new instance with the provided - /// , . + /// . /// - internal ObjectHttpResult(object? value, int? statusCode) - : this(value, statusCode, contentType: null) + public ObjectHttpResult(object? value) { + Value = value; + + if (value is ProblemDetails problemDetails) + { + HttpResultsHelper.ApplyProblemDetailsDefaults(problemDetails, null); + StatusCode = problemDetails.Status; + } } /// /// Creates a new instance with the provided - /// , and . + /// , . /// - internal ObjectHttpResult(object? value, int? statusCode, string? contentType) + public ObjectHttpResult(object? value, int statusCode) { Value = value; + StatusCode = statusCode; if (value is ProblemDetails problemDetails) { HttpResultsHelper.ApplyProblemDetailsDefaults(problemDetails, statusCode); - statusCode ??= problemDetails.Status; } - - StatusCode = statusCode; - ContentType = contentType; } /// /// Gets the object result. /// - public object? Value { get; internal init; } + public object? Value { get; } /// - /// Gets or sets the value for the Content-Type header. + /// Gets the HTTP status code. /// - public string? ContentType { get; internal init; } + public int? StatusCode { get; } /// - /// Gets the HTTP status code. + /// Gets or sets the value for the Content-Type header. /// - public int? StatusCode { get; internal init; } + public string? ContentType { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/OkObjectHttpResult.cs b/src/Http/Http.Results/src/OkObjectHttpResult.cs index 2dedc139d7ab..cca6f074f05b 100644 --- a/src/Http/Http.Results/src/OkObjectHttpResult.cs +++ b/src/Http/Http.Results/src/OkObjectHttpResult.cs @@ -17,16 +17,21 @@ public sealed class OkObjectHttpResult : IResult /// Initializes a new instance of the class with the values. /// /// The value to format in the entity body. - internal OkObjectHttpResult(object? value) + public OkObjectHttpResult(object? value = null) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a . + /// + public static OkObjectHttpResult Empty { get; } = new(); + /// /// Gets the object result. /// - public object? Value { get; internal init; } + public object? Value { get; } /// /// Gets the HTTP status code. @@ -36,6 +41,7 @@ internal OkObjectHttpResult(object? value) /// public Task ExecuteAsync(HttpContext httpContext) { + // Creating the logger with a string to preserve the category after the refactoring. var loggerFactory = httpContext.RequestServices.GetRequiredService(); var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.OkObjectResult"); diff --git a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs index 97f8e01dca38..e323ecc45b4a 100644 --- a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs +++ b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs @@ -13,30 +13,14 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class PhysicalFileHttpResult : IResult { - /// - /// Creates a new instance with - /// the provided and the provided . - /// - /// The path to the file. The path must be an absolute path. - /// The Content-Type header of the response. - internal PhysicalFileHttpResult(string fileName, string? contentType) - : this(fileName, contentType, fileDownloadName: null) - { - } + private DateTimeOffset? _lastModified; /// - /// Creates a new instance with - /// the provided , the provided - /// and the provided . + /// Creates a new instance with the provided values. /// /// The path to the file. The path must be an absolute path. - /// The Content-Type header of the response. - /// The suggested file name. - internal PhysicalFileHttpResult( - string fileName, - string? contentType, - string? fileDownloadName) - : this(fileName, contentType, fileDownloadName, enableRangeProcessing: false) + public PhysicalFileHttpResult(string fileName) + : this(fileName, contentType: null) { } @@ -45,60 +29,50 @@ internal PhysicalFileHttpResult( /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. - internal PhysicalFileHttpResult( - string fileName, - string? contentType, - string? fileDownloadName, - bool enableRangeProcessing, - DateTimeOffset? lastModified = null, - EntityTagHeaderValue? entityTag = null) + public PhysicalFileHttpResult(string fileName, string? contentType) { - FileName = fileName; + FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); ContentType = contentType ?? "application/octet-stream"; - FileDownloadName = fileDownloadName; - EnableRangeProcessing = enableRangeProcessing; - LastModified = lastModified; - EntityTag = entityTag; } /// - /// Gets the Content-Type header for the response. + /// Gets or sets the path to the file that will be sent back as the response. /// - public string ContentType { get; internal set; } + public string FileName { get; } /// - /// Gets the file name that will be used in the Content-Disposition header of the response. + /// Gets or sets the file length information . /// - public string? FileDownloadName { get; internal set; } + public long? FileLength { get; private set; } /// - /// Gets the last modified information associated with the file result. + /// Gets the Content-Type header for the response. /// - public DateTimeOffset? LastModified { get; internal set; } + public string ContentType { get; init; } /// - /// Gets the etag associated with the file result. + /// Gets the value that enables range processing for the file result. /// - public EntityTagHeaderValue? EntityTag { get; internal init; } + public bool EnableRangeProcessing { get; init; } /// - /// Gets the value that enables range processing for the file result. + /// Gets the etag associated with the file result. /// - public bool EnableRangeProcessing { get; internal init; } + public EntityTagHeaderValue? EntityTag { get; init; } /// - /// Gets or sets the file length information . + /// Gets the file name that will be used in the Content-Disposition header of the response. /// - public long? FileLength { get; internal set; } + public string? FileDownloadName { get; init; } /// - /// Gets or sets the path to the file that will be sent back as the response. + /// Gets the last modified information associated with the file result. /// - public string FileName { get; } + public DateTimeOffset? LastModified + { + get => _lastModified; + init => _lastModified = value; + } // For testing internal Func GetFileInfoWrapper { get; init; } = @@ -113,7 +87,7 @@ public Task ExecuteAsync(HttpContext httpContext) throw new FileNotFoundException($"Could not find file: {FileName}", FileName); } - LastModified ??= fileInfo.LastWriteTimeUtc; + _lastModified ??= fileInfo.LastWriteTimeUtc; FileLength = fileInfo.Length; // Creating the logger with a string to preserve the category after the refactoring. diff --git a/src/Http/Http.Results/src/ProblemHttpResult.cs b/src/Http/Http.Results/src/ProblemHttpResult.cs index 0a5c52a0fcca..ad40be60c971 100644 --- a/src/Http/Http.Results/src/ProblemHttpResult.cs +++ b/src/Http/Http.Results/src/ProblemHttpResult.cs @@ -18,12 +18,49 @@ public sealed class ProblemHttpResult : IResult /// the provided . /// /// The instance to format in the entity body. - internal ProblemHttpResult(ProblemDetails problemDetails) + public ProblemHttpResult(ProblemDetails problemDetails) { ProblemDetails = problemDetails; HttpResultsHelper.ApplyProblemDetailsDefaults(ProblemDetails, statusCode: null); } + /// + /// Creates a new instance with + /// the provided values. + /// + /// The value for . + /// The value for . + /// The value for . + /// The value for . + /// The value for . + /// The value for . + /// The created for the response. + public ProblemHttpResult( + string? detail = null, + string? instance = null, + int? statusCode = null, + string? title = null, + string? type = null, + IDictionary? extensions = null) + { + ProblemDetails = new ProblemDetails + { + Detail = detail, + Instance = instance, + Status = statusCode, + Title = title, + Type = type, + }; + + if (extensions is not null) + { + foreach (var extension in extensions) + { + ProblemDetails.Extensions.Add(extension); + } + } + } + /// /// Gets the instance. /// diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index b53f85370ac8..3a04ba241428 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -1,39 +1,62 @@ #nullable enable Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult +Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.AcceptedAtRouteHttpResult(string? routeName = null, object? routeValues = null, object? value = null) -> void Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary! Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.AcceptedHttpResult +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(System.Uri! locationUri) -> void +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(System.Uri! locationUri, object? value) -> void +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(string? location) -> void +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(string? location, object? value) -> void Microsoft.AspNetCore.Http.AcceptedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.AcceptedHttpResult.Location.get -> string? Microsoft.AspNetCore.Http.AcceptedHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.AcceptedHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.BadRequestObjectHttpResult +Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.BadRequestObjectHttpResult(object? error = null) -> void Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ChallengeHttpResult Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! +Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.init -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult() -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ChallengeHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.ConflictObjectHttpResult +Microsoft.AspNetCore.Http.ConflictObjectHttpResult.ConflictObjectHttpResult(object? error = null) -> void Microsoft.AspNetCore.Http.ConflictObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ConflictObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ContentHttpResult Microsoft.AspNetCore.Http.ContentHttpResult.Content.get -> string? +Microsoft.AspNetCore.Http.ContentHttpResult.Content.init -> void +Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult() -> void +Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content) -> void +Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content, string! contentType) -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentType.get -> string? +Microsoft.AspNetCore.Http.ContentHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.ContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ContentHttpResult.StatusCode.get -> int? +Microsoft.AspNetCore.Http.ContentHttpResult.StatusCode.init -> void Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult +Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.CreatedAtRouteHttpResult(string? routeName = null, object? routeValues = null, object? value = null) -> void Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.CreatedHttpResult +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(System.Uri! locationUri) -> void +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(System.Uri! locationUri, object? value) -> void +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(string? location) -> void +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(string? location, object? value) -> void Microsoft.AspNetCore.Http.CreatedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.CreatedHttpResult.Location.get -> string? Microsoft.AspNetCore.Http.CreatedHttpResult.StatusCode.get -> int @@ -42,108 +65,186 @@ Microsoft.AspNetCore.Http.EmptyHttpResult Microsoft.AspNetCore.Http.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.FileContentHttpResult Microsoft.AspNetCore.Http.FileContentHttpResult.ContentType.get -> string! +Microsoft.AspNetCore.Http.FileContentHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.EnableRangeProcessing.get -> bool +Microsoft.AspNetCore.Http.FileContentHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? +Microsoft.AspNetCore.Http.FileContentHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.FileContentHttpResult.FileContentHttpResult(System.ReadOnlyMemory fileContents) -> void +Microsoft.AspNetCore.Http.FileContentHttpResult.FileContentHttpResult(System.ReadOnlyMemory fileContents, string? contentType) -> void Microsoft.AspNetCore.Http.FileContentHttpResult.FileContents.get -> System.ReadOnlyMemory Microsoft.AspNetCore.Http.FileContentHttpResult.FileDownloadName.get -> string? +Microsoft.AspNetCore.Http.FileContentHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.FileContentHttpResult.LastModified.get -> System.DateTimeOffset? +Microsoft.AspNetCore.Http.FileContentHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult Microsoft.AspNetCore.Http.FileStreamHttpResult.ContentType.get -> string! +Microsoft.AspNetCore.Http.FileStreamHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.EnableRangeProcessing.get -> bool +Microsoft.AspNetCore.Http.FileStreamHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? +Microsoft.AspNetCore.Http.FileStreamHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.FileStreamHttpResult.FileDownloadName.get -> string? +Microsoft.AspNetCore.Http.FileStreamHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStream.get -> System.IO.Stream! +Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStreamHttpResult(System.IO.Stream! fileStream) -> void +Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStreamHttpResult(System.IO.Stream! fileStream, string? contentType) -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.get -> System.DateTimeOffset? +Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult Microsoft.AspNetCore.Http.ForbidHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! +Microsoft.AspNetCore.Http.ForbidHttpResult.AuthenticationSchemes.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult() -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void Microsoft.AspNetCore.Http.ForbidHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.JsonHttpResult Microsoft.AspNetCore.Http.JsonHttpResult.ContentType.get -> string? +Microsoft.AspNetCore.Http.JsonHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value) -> void +Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions) -> void Microsoft.AspNetCore.Http.JsonHttpResult.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions? +Microsoft.AspNetCore.Http.JsonHttpResult.JsonSerializerOptions.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.get -> int? +Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.NoContentHttpResult Microsoft.AspNetCore.Http.NoContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.NoContentHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.NotFoundObjectHttpResult Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.NotFoundObjectHttpResult(object? value = null) -> void Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.OkObjectHttpResult Microsoft.AspNetCore.Http.OkObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.OkObjectHttpResult.OkObjectHttpResult(object? value = null) -> void Microsoft.AspNetCore.Http.OkObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.OkObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.PhysicalFileHttpResult Microsoft.AspNetCore.Http.PhysicalFileHttpResult.ContentType.get -> string! +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EnableRangeProcessing.get -> bool +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileDownloadName.get -> string? +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.PhysicalFileHttpResult.LastModified.get -> System.DateTimeOffset? +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.LastModified.init -> void +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.PhysicalFileHttpResult(string! fileName) -> void +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.PhysicalFileHttpResult(string! fileName, string? contentType) -> void Microsoft.AspNetCore.Http.ProblemHttpResult Microsoft.AspNetCore.Http.ProblemHttpResult.ContentType.get -> string! Microsoft.AspNetCore.Http.ProblemHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ProblemHttpResult.ProblemDetails.get -> Microsoft.AspNetCore.Mvc.ProblemDetails! +Microsoft.AspNetCore.Http.ProblemHttpResult.ProblemHttpResult(Microsoft.AspNetCore.Mvc.ProblemDetails! problemDetails) -> void +Microsoft.AspNetCore.Http.ProblemHttpResult.ProblemHttpResult(string? detail = null, string? instance = null, int? statusCode = null, string? title = null, string? type = null, System.Collections.Generic.IDictionary? extensions = null) -> void Microsoft.AspNetCore.Http.ProblemHttpResult.StatusCode.get -> int? Microsoft.AspNetCore.Http.PushStreamHttpResult Microsoft.AspNetCore.Http.PushStreamHttpResult.ContentType.get -> string! +Microsoft.AspNetCore.Http.PushStreamHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.EnableRangeProcessing.get -> bool +Microsoft.AspNetCore.Http.PushStreamHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? +Microsoft.AspNetCore.Http.PushStreamHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.PushStreamHttpResult.FileDownloadName.get -> string? +Microsoft.AspNetCore.Http.PushStreamHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.FileLength.get -> long? +Microsoft.AspNetCore.Http.PushStreamHttpResult.FileLength.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.LastModified.get -> System.DateTimeOffset? +Microsoft.AspNetCore.Http.PushStreamHttpResult.LastModified.init -> void +Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback) -> void +Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback, string? contentType) -> void Microsoft.AspNetCore.Http.RedirectHttpResult Microsoft.AspNetCore.Http.RedirectHttpResult.AcceptLocalUrlOnly.get -> bool +Microsoft.AspNetCore.Http.RedirectHttpResult.AcceptLocalUrlOnly.init -> void Microsoft.AspNetCore.Http.RedirectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.get -> bool +Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.init -> void Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.get -> bool +Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.init -> void +Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url, bool permanent = false, bool preserveMethod = false, bool acceptLocalUrlOnly = false) -> void Microsoft.AspNetCore.Http.RedirectHttpResult.Url.get -> string! Microsoft.AspNetCore.Http.RedirectToRouteHttpResult Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Fragment.get -> string? +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Fragment.init -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.get -> bool +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.init -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.init -> void +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(object! routeValues) -> void +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string! routeName) -> void +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string? routeName, object? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? Microsoft.AspNetCore.Http.SignInHttpResult Microsoft.AspNetCore.Http.SignInHttpResult.AuthenticationScheme.get -> string? +Microsoft.AspNetCore.Http.SignInHttpResult.AuthenticationScheme.init -> void Microsoft.AspNetCore.Http.SignInHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.SignInHttpResult.Principal.get -> System.Security.Claims.ClaimsPrincipal! Microsoft.AspNetCore.Http.SignInHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? +Microsoft.AspNetCore.Http.SignInHttpResult.Properties.init -> void +Microsoft.AspNetCore.Http.SignInHttpResult.SignInHttpResult(System.Security.Claims.ClaimsPrincipal! principal, string? authenticationScheme = null, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null) -> void Microsoft.AspNetCore.Http.SignOutHttpResult Microsoft.AspNetCore.Http.SignOutHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! +Microsoft.AspNetCore.Http.SignOutHttpResult.AuthenticationSchemes.init -> void Microsoft.AspNetCore.Http.SignOutHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.SignOutHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult() -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void Microsoft.AspNetCore.Http.StatusCodeHttpResult Microsoft.AspNetCore.Http.StatusCodeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.StatusCodeHttpResult.StatusCode.get -> int +Microsoft.AspNetCore.Http.StatusCodeHttpResult.StatusCodeHttpResult(int statusCode) -> void Microsoft.AspNetCore.Http.UnauthorizedHttpResult Microsoft.AspNetCore.Http.UnauthorizedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.UnauthorizedHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.StatusCode.get -> int +Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.UnprocessableEntityObjectHttpResult(object? value = null) -> void Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.VirtualFileHttpResult Microsoft.AspNetCore.Http.VirtualFileHttpResult.ContentType.get -> string! +Microsoft.AspNetCore.Http.VirtualFileHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.EnableRangeProcessing.get -> bool +Microsoft.AspNetCore.Http.VirtualFileHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? +Microsoft.AspNetCore.Http.VirtualFileHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileDownloadName.get -> string? +Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.get -> System.DateTimeOffset? +Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.init -> void +Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName) -> void +Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName, string? contentType) -> void +static Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.Empty.get -> Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult! +static Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.BadRequestObjectHttpResult! +static Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.ConflictObjectHttpResult! +static Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.Empty.get -> Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult! static Microsoft.AspNetCore.Http.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.EmptyHttpResult! +static Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.NotFoundObjectHttpResult! +static Microsoft.AspNetCore.Http.OkObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.OkObjectHttpResult! static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! +static Microsoft.AspNetCore.Http.UnauthorizedHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnauthorizedHttpResult! +static Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult! diff --git a/src/Http/Http.Results/src/PushStreamHttpResult.cs b/src/Http/Http.Results/src/PushStreamHttpResult.cs index 71f454af2bf2..fde14fad3b85 100644 --- a/src/Http/Http.Results/src/PushStreamHttpResult.cs +++ b/src/Http/Http.Results/src/PushStreamHttpResult.cs @@ -16,29 +16,11 @@ public sealed class PushStreamHttpResult : IResult private readonly Func _streamWriterCallback; /// - /// Creates a new instance with - /// the provided and the provided . - /// - /// The stream writer callback. - /// The Content-Type header of the response. - internal PushStreamHttpResult(Func streamWriterCallback, string? contentType) - : this(streamWriterCallback, contentType, fileDownloadName: null) - { - } - - /// - /// Creates a new instance with - /// the provided , the provided - /// and the provided . + /// Creates a new instance with the provided values. /// /// The stream writer callback. - /// The Content-Type header of the response. - /// The suggested file name. - internal PushStreamHttpResult( - Func streamWriterCallback, - string? contentType, - string? fileDownloadName) - : this(streamWriterCallback, contentType, fileDownloadName, enableRangeProcessing: false) + public PushStreamHttpResult(Func streamWriterCallback) + : this(streamWriterCallback, contentType: null) { } @@ -47,55 +29,41 @@ internal PushStreamHttpResult( /// /// The stream writer callback. /// The Content-Type header of the response. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. - internal PushStreamHttpResult( - Func streamWriterCallback, - string? contentType, - string? fileDownloadName, - bool enableRangeProcessing, - DateTimeOffset? lastModified = null, - EntityTagHeaderValue? entityTag = null) + public PushStreamHttpResult(Func streamWriterCallback, string? contentType) { _streamWriterCallback = streamWriterCallback; ContentType = contentType ?? "application/octet-stream"; - FileDownloadName = fileDownloadName; - EnableRangeProcessing = enableRangeProcessing; - LastModified = lastModified; - EntityTag = entityTag; } /// - /// Gets the Content-Type header for the response. + /// Gets or sets the file length information . /// - public string ContentType { get; internal set; } + public long? FileLength { get; init; } /// - /// Gets the file name that will be used in the Content-Disposition header of the response. + /// Gets the Content-Type header for the response. /// - public string? FileDownloadName { get; internal set; } + public string ContentType { get; init; } /// - /// Gets the last modified information associated with the file result. + /// Gets the value that enables range processing for the file result. /// - public DateTimeOffset? LastModified { get; internal set; } + public bool EnableRangeProcessing { get; init; } /// /// Gets the etag associated with the file result. /// - public EntityTagHeaderValue? EntityTag { get; internal init; } + public EntityTagHeaderValue? EntityTag { get; init; } /// - /// Gets the value that enables range processing for the file result. + /// Gets the file name that will be used in the Content-Disposition header of the response. /// - public bool EnableRangeProcessing { get; internal init; } + public string? FileDownloadName { get; init; } /// - /// Gets or sets the file length information . + /// Gets the last modified information associated with the file result. /// - public long? FileLength { get; internal set; } + public DateTimeOffset? LastModified { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/RedirectHttpResult.cs b/src/Http/Http.Results/src/RedirectHttpResult.cs index 3c1bdc6ce911..d8165be5e3c1 100644 --- a/src/Http/Http.Results/src/RedirectHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectHttpResult.cs @@ -13,39 +13,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class RedirectHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The URL to redirect to. - internal RedirectHttpResult(string url) - : this(url, permanent: false) - { - } - - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The URL to redirect to. - /// Specifies whether the redirect should be permanent (301) or temporary (302). - internal RedirectHttpResult(string url, bool permanent) - : this(url, permanent, preserveMethod: false) - { - } - - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The URL to redirect to. - /// Specifies whether the redirect should be permanent (301) or temporary (302). - /// If set to true, make the temporary redirect (307) - /// or permanent redirect (308) preserve the initial request method. - internal RedirectHttpResult(string url, bool permanent, bool preserveMethod) - : this(url, acceptLocalUrlOnly: false, permanent, preserveMethod) - { } - /// /// Initializes a new instance of the class with the values /// provided. @@ -56,7 +23,11 @@ internal RedirectHttpResult(string url, bool permanent, bool preserveMethod) /// or permanent redirect (308) preserve the initial request method. /// If set to true, only local URLs are accepted /// and will throw an exception when the supplied URL is not considered local. - internal RedirectHttpResult(string url, bool acceptLocalUrlOnly, bool permanent, bool preserveMethod) + public RedirectHttpResult( + string url, + bool permanent = false, + bool preserveMethod = false, + bool acceptLocalUrlOnly = false) { if (url == null) { @@ -75,24 +46,24 @@ internal RedirectHttpResult(string url, bool acceptLocalUrlOnly, bool permanent, } /// - /// Gets the value that specifies that the redirect should be permanent if true or temporary if false. + /// Gets the URL to redirect to. /// - public bool Permanent { get; } + public string Url { get; } /// - /// Gets an indication that the redirect preserves the initial request method. + /// Gets the value that specifies that the redirect should be permanent if true or temporary if false. /// - public bool PreserveMethod { get; } + public bool Permanent { get; init; } /// - /// Gets the URL to redirect to. + /// Gets an indication that the redirect preserves the initial request method. /// - public string Url { get; } + public bool PreserveMethod { get; init; } /// /// Gets an indication that only local URLs are accepted. /// - public bool AcceptLocalUrlOnly { get; } + public bool AcceptLocalUrlOnly { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs index 586694792e59..35e533054c5b 100644 --- a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs @@ -19,91 +19,18 @@ public sealed partial class RedirectToRouteHttpResult : IResult /// provided. /// /// The parameters for the route. - internal RedirectToRouteHttpResult(object? routeValues) - : this(routeName: null, routeValues: routeValues) - { - } - - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The name of the route. - /// The parameters for the route. - internal RedirectToRouteHttpResult( - string? routeName, - object? routeValues) - : this(routeName, routeValues, permanent: false) - { - } - - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The name of the route. - /// The parameters for the route. - /// If set to true, makes the redirect permanent (301). - /// Otherwise a temporary redirect is used (302). - internal RedirectToRouteHttpResult( - string? routeName, - object? routeValues, - bool permanent) - : this(routeName, routeValues, permanent, fragment: null) - { - } - - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The name of the route. - /// The parameters for the route. - /// If set to true, makes the redirect permanent (301). - /// Otherwise a temporary redirect is used (302). - /// If set to true, make the temporary redirect (307) - /// or permanent redirect (308) preserve the initial request method. - internal RedirectToRouteHttpResult( - string? routeName, - object? routeValues, - bool permanent, - bool preserveMethod) - : this(routeName, routeValues, permanent, preserveMethod, fragment: null) - { - } - - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The name of the route. - /// The parameters for the route. - /// The fragment to add to the URL. - internal RedirectToRouteHttpResult( - string? routeName, - object? routeValues, - string? fragment) - : this(routeName, routeValues, permanent: false, fragment: fragment) - { - } + public RedirectToRouteHttpResult(object routeValues) + : this(routeName: null, routeValues) + { } /// /// Initializes a new instance of the with the values /// provided. /// /// The name of the route. - /// The parameters for the route. - /// If set to true, makes the redirect permanent (301). - /// Otherwise a temporary redirect is used (302). - /// The fragment to add to the URL. - internal RedirectToRouteHttpResult( - string? routeName, - object? routeValues, - bool permanent, - string? fragment) - : this(routeName, routeValues, permanent, preserveMethod: false, fragment: fragment) - { - } + public RedirectToRouteHttpResult(string routeName) + : this(routeName, routeValues: null) + { } /// /// Initializes a new instance of the with the values @@ -116,12 +43,12 @@ internal RedirectToRouteHttpResult( /// If set to true, make the temporary redirect (307) /// or permanent redirect (308) preserve the initial request method. /// The fragment to add to the URL. - internal RedirectToRouteHttpResult( + public RedirectToRouteHttpResult( string? routeName, object? routeValues, - bool permanent, - bool preserveMethod, - string? fragment) + bool permanent = false, + bool preserveMethod = false, + string? fragment = null) { RouteName = routeName; RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues); @@ -143,17 +70,17 @@ internal RedirectToRouteHttpResult( /// /// Gets the value that specifies that the redirect should be permanent if true or temporary if false. /// - public bool Permanent { get; } + public bool Permanent { get; init; } /// /// Gets an indication that the redirect preserves the initial request method. /// - public bool PreserveMethod { get; } + public bool PreserveMethod { get; init; } /// /// Gets the fragment to add to the URL. /// - public string? Fragment { get; } + public string? Fragment { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/Results.cs b/src/Http/Http.Results/src/Results.cs index 89b9c12bde7d..991a7512f675 100644 --- a/src/Http/Http.Results/src/Results.cs +++ b/src/Http/Http.Results/src/Results.cs @@ -114,7 +114,10 @@ public static IResult Text(string content, string? contentType = null, Encoding? mediaTypeHeaderValue.Encoding = contentEncoding ?? mediaTypeHeaderValue.Encoding; } - return new ContentHttpResult(content, mediaTypeHeaderValue?.ToString()); + return new ContentHttpResult(content) + { + ContentType = mediaTypeHeaderValue?.ToString(), + }; } /// @@ -138,8 +141,9 @@ public static IResult Content(string content, MediaTypeHeaderValue contentType) /// Callers should cache an instance of serializer settings to avoid /// recreating cached data with each call. public static IResult Json(object? data, JsonSerializerOptions? options = null, string? contentType = null, int? statusCode = null) - => new JsonHttpResult(data, statusCode, options) + => new JsonHttpResult(data, options) { + StatusCode = statusCode, ContentType = contentType, }; @@ -464,7 +468,7 @@ public static IResult Redirect(string url, bool permanent = false, bool preserve /// If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the initial request method. /// The created for the response. public static IResult LocalRedirect(string localUrl, bool permanent = false, bool preserveMethod = false) - => new RedirectHttpResult(localUrl, acceptLocalUrlOnly: true, permanent, preserveMethod); + => new RedirectHttpResult(localUrl, permanent, preserveMethod, acceptLocalUrlOnly: true); /// /// Redirects to the specified route. @@ -503,14 +507,14 @@ public static IResult StatusCode(int statusCode) /// The value to be included in the HTTP response body. /// The created for the response. public static IResult NotFound(object? value = null) - => new NotFoundObjectHttpResult(value); + => value is null ? NotFoundObjectHttpResult.Empty : new NotFoundObjectHttpResult(value); /// /// Produces a response. /// /// The created for the response. public static IResult Unauthorized() - => new UnauthorizedHttpResult(); + => UnauthorizedHttpResult.Instance; /// /// Produces a response. @@ -518,7 +522,7 @@ public static IResult Unauthorized() /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult BadRequest(object? error = null) - => new BadRequestObjectHttpResult(error); + => error is null ? BadRequestObjectHttpResult.Empty : new BadRequestObjectHttpResult(error); /// /// Produces a response. @@ -526,14 +530,14 @@ public static IResult BadRequest(object? error = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult Conflict(object? error = null) - => new ConflictObjectHttpResult(error); + => error is null ? ConflictObjectHttpResult.Empty : new ConflictObjectHttpResult(error); /// /// Produces a response. /// /// The created for the response. public static IResult NoContent() - => new NoContentHttpResult(); + => NoContentHttpResult.Instance; /// /// Produces a response. @@ -541,7 +545,7 @@ public static IResult NoContent() /// The value to be included in the HTTP response body. /// The created for the response. public static IResult Ok(object? value = null) - => new OkObjectHttpResult(value); + => value is null ? OkObjectHttpResult.Empty : new OkObjectHttpResult(value); /// /// Produces a response. @@ -549,7 +553,7 @@ public static IResult Ok(object? value = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult UnprocessableEntity(object? error = null) - => new UnprocessableEntityObjectHttpResult(error); + => error is null ? UnprocessableEntityObjectHttpResult.Empty : new UnprocessableEntityObjectHttpResult(error); /// /// Produces a response. @@ -569,24 +573,7 @@ public static IResult Problem( string? type = null, IDictionary? extensions = null) { - var problemDetails = new ProblemDetails - { - Detail = detail, - Instance = instance, - Status = statusCode, - Title = title, - Type = type, - }; - - if (extensions is not null) - { - foreach (var extension in extensions) - { - problemDetails.Extensions.Add(extension); - } - } - - return new ProblemHttpResult(problemDetails); + return new ProblemHttpResult(detail, instance, statusCode, title, type, extensions); } /// diff --git a/src/Http/Http.Results/src/SignInHttpResult.cs b/src/Http/Http.Results/src/SignInHttpResult.cs index a1b0d805e867..1fc2a6aa0b20 100644 --- a/src/Http/Http.Results/src/SignInHttpResult.cs +++ b/src/Http/Http.Results/src/SignInHttpResult.cs @@ -13,16 +13,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class SignInHttpResult : IResult { - /// - /// Initializes a new instance of with the - /// default authentication scheme. - /// - /// The claims principal containing the user claims. - internal SignInHttpResult(ClaimsPrincipal principal) - : this(principal, authenticationScheme: null, properties: null) - { - } - /// /// Initializes a new instance of with the /// specified authentication scheme and . @@ -30,7 +20,10 @@ internal SignInHttpResult(ClaimsPrincipal principal) /// The claims principal containing the user claims. /// The authentication schemes to use when signing in the user. /// used to perform the sign-in operation. - internal SignInHttpResult(ClaimsPrincipal principal, string? authenticationScheme, AuthenticationProperties? properties) + public SignInHttpResult( + ClaimsPrincipal principal, + string? authenticationScheme = null, + AuthenticationProperties? properties = null) { Principal = principal ?? throw new ArgumentNullException(nameof(principal)); AuthenticationScheme = authenticationScheme; @@ -38,19 +31,19 @@ internal SignInHttpResult(ClaimsPrincipal principal, string? authenticationSchem } /// - /// Gets or sets the authentication scheme that is used to perform the sign-in operation. + /// Gets or sets the containing the user claims. /// - public string? AuthenticationScheme { get; internal init; } + public ClaimsPrincipal Principal { get; } /// - /// Gets or sets the containing the user claims. + /// Gets or sets the authentication scheme that is used to perform the sign-in operation. /// - public ClaimsPrincipal Principal { get; internal init; } + public string? AuthenticationScheme { get; init; } /// /// Gets or sets the used to perform the sign-in operation. /// - public AuthenticationProperties? Properties { get; internal init; } + public AuthenticationProperties? Properties { get; init; } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/SignOutHttpResult.cs b/src/Http/Http.Results/src/SignOutHttpResult.cs index 7d187fe52c15..da7f05f97e50 100644 --- a/src/Http/Http.Results/src/SignOutHttpResult.cs +++ b/src/Http/Http.Results/src/SignOutHttpResult.cs @@ -16,38 +16,19 @@ public sealed partial class SignOutHttpResult : IResult /// /// Initializes a new instance of with the default sign out scheme. /// - internal SignOutHttpResult() - : this(Array.Empty()) - { - } - - /// - /// Initializes a new instance of with the default sign out scheme. - /// specified authentication scheme and . - /// - /// used to perform the sign-out operation. - internal SignOutHttpResult(AuthenticationProperties properties) - : this(Array.Empty(), properties) - { - } - - /// - /// Initializes a new instance of with the - /// specified authentication scheme. - /// - /// The authentication scheme to use when signing out the user. - internal SignOutHttpResult(string authenticationScheme) - : this(new[] { authenticationScheme }) + public SignOutHttpResult() + : this(authenticationSchemes: Array.Empty(), properties: null) { } /// /// Initializes a new instance of with the - /// specified authentication schemes. + /// specified . /// - /// The authentication schemes to use when signing out the user. - internal SignOutHttpResult(IList authenticationSchemes) - : this(authenticationSchemes, properties: null) + /// used to perform the authentication + /// challenge. + public SignOutHttpResult(AuthenticationProperties? properties) + : this(Array.Empty(), properties) { } @@ -55,9 +36,10 @@ internal SignOutHttpResult(IList authenticationSchemes) /// Initializes a new instance of with the /// specified authentication scheme and . /// - /// The authentication schemes to use when signing out the user. - /// used to perform the sign-out operation. - internal SignOutHttpResult(string authenticationScheme, AuthenticationProperties? properties) + /// The authentication schemes to challenge. + /// used to perform the authentication + /// challenge. + public SignOutHttpResult(string authenticationScheme, AuthenticationProperties? properties) : this(new[] { authenticationScheme }, properties) { } @@ -66,15 +48,11 @@ internal SignOutHttpResult(string authenticationScheme, AuthenticationProperties /// Initializes a new instance of with the /// specified authentication schemes and . /// - /// The authentication scheme to use when signing out the user. - /// used to perform the sign-out operation. - internal SignOutHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + /// The authentication scheme to challenge. + /// used to perform the authentication + /// challenge. + public SignOutHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) { - if (authenticationSchemes is null) - { - throw new ArgumentNullException(nameof(authenticationSchemes)); - } - AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; } @@ -82,12 +60,12 @@ internal SignOutHttpResult(IList authenticationSchemes, AuthenticationPr /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; internal init; } + public IReadOnlyList AuthenticationSchemes { get; init; } /// /// Gets the used to perform the sign-out operation. /// - public AuthenticationProperties? Properties { get; internal init; } + public AuthenticationProperties? Properties { get; } /// public async Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/StatusCodeHttpResult.cs b/src/Http/Http.Results/src/StatusCodeHttpResult.cs index 3e24b45a7767..a6422912b6ef 100644 --- a/src/Http/Http.Results/src/StatusCodeHttpResult.cs +++ b/src/Http/Http.Results/src/StatusCodeHttpResult.cs @@ -17,7 +17,7 @@ public sealed partial class StatusCodeHttpResult : IResult /// with the given . /// /// The HTTP status code of the response. - internal StatusCodeHttpResult(int statusCode) + public StatusCodeHttpResult(int statusCode) { StatusCode = statusCode; } diff --git a/src/Http/Http.Results/src/UnauthorizedHttpResult.cs b/src/Http/Http.Results/src/UnauthorizedHttpResult.cs index 79bc2c17dd91..4dcfa62e11fe 100644 --- a/src/Http/Http.Results/src/UnauthorizedHttpResult.cs +++ b/src/Http/Http.Results/src/UnauthorizedHttpResult.cs @@ -15,10 +15,15 @@ public sealed class UnauthorizedHttpResult : IResult /// /// Initializes a new instance of the class. /// - internal UnauthorizedHttpResult() + private UnauthorizedHttpResult() { } + /// + /// Gets an instance of . + /// + public static UnauthorizedHttpResult Instance { get; } = new(); + /// /// Gets the HTTP status code. /// diff --git a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs index d1c8eda62dae..4fd2ab7eea0c 100644 --- a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs +++ b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs @@ -17,12 +17,17 @@ public sealed class UnprocessableEntityObjectHttpResult : IResult /// provided. /// /// The value to format in the entity body. - internal UnprocessableEntityObjectHttpResult(object? value) + public UnprocessableEntityObjectHttpResult(object? value = null) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } + /// + /// Gets an instance of without a . + /// + public static UnprocessableEntityObjectHttpResult Empty { get; } = new(); + /// public object? Value { get; internal init; } diff --git a/src/Http/Http.Results/src/VirtualFileHttpResult.cs b/src/Http/Http.Results/src/VirtualFileHttpResult.cs index cac64665d23d..d3670e1e022b 100644 --- a/src/Http/Http.Results/src/VirtualFileHttpResult.cs +++ b/src/Http/Http.Results/src/VirtualFileHttpResult.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -16,32 +15,14 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class VirtualFileHttpResult : IResult { - private string _fileName; + private DateTimeOffset? _lastModified; /// - /// Creates a new instance with - /// the provided and the provided . - /// - /// The path to the file. The path must be an absolute path. - /// The Content-Type header of the response. - internal VirtualFileHttpResult(string fileName, string? contentType) - : this(fileName, contentType, fileDownloadName: null) - { - } - - /// - /// Creates a new instance with - /// the provided , the provided - /// and the provided . + /// Creates a new instance with the provided values. /// /// The path to the file. The path must be an absolute path. - /// The Content-Type header of the response. - /// The suggested file name. - internal VirtualFileHttpResult( - string fileName, - string? contentType, - string? fileDownloadName) - : this(fileName, contentType, fileDownloadName, enableRangeProcessing: false) + public VirtualFileHttpResult(string fileName) + : this(fileName, contentType: null) { } @@ -50,52 +31,49 @@ internal VirtualFileHttpResult( /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. - internal VirtualFileHttpResult( - string fileName, - string? contentType, - string? fileDownloadName, - bool enableRangeProcessing, - DateTimeOffset? lastModified = null, - EntityTagHeaderValue? entityTag = null) + public VirtualFileHttpResult(string fileName, string? contentType) { FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); ContentType = contentType ?? "application/octet-stream"; - FileDownloadName = fileDownloadName; - EnableRangeProcessing = enableRangeProcessing; - LastModified = lastModified; - EntityTag = entityTag; } - /// - public string ContentType { get; internal set; } + /// + /// Gets or sets the path to the file that will be sent back as the response. + /// + public string FileName { get; } - /// - public string? FileDownloadName { get; internal set; } + /// + /// Gets or sets the file length information . + /// + public long? FileLength { get; private set; } - /// - public DateTimeOffset? LastModified { get; internal set; } + /// + /// Gets the Content-Type header for the response. + /// + public string ContentType { get; init; } - /// - public EntityTagHeaderValue? EntityTag { get; internal init; } + /// + /// Gets the value that enables range processing for the file result. + /// + public bool EnableRangeProcessing { get; init; } - /// - public bool EnableRangeProcessing { get; internal init; } + /// + /// Gets the etag associated with the file result. + /// + public EntityTagHeaderValue? EntityTag { get; init; } - /// - public long? FileLength { get; internal set; } + /// + /// Gets the file name that will be used in the Content-Disposition header of the response. + /// + public string? FileDownloadName { get; init; } /// - /// Gets or sets the path to the file that will be sent back as the response. + /// Gets the last modified information associated with the file result. /// - public string FileName + public DateTimeOffset? LastModified { - get => _fileName; - [MemberNotNull(nameof(_fileName))] - internal set => _fileName = value ?? throw new ArgumentNullException(nameof(value)); + get => _lastModified; + init => _lastModified = value; } /// @@ -108,7 +86,7 @@ public Task ExecuteAsync(HttpContext httpContext) { throw new FileNotFoundException($"Could not find file: {FileName}.", FileName); } - LastModified = LastModified ?? fileInfo.LastModified; + _lastModified = LastModified ?? fileInfo.LastModified; FileLength = fileInfo.Length; // Creating the logger with a string to preserve the category after the refactoring. diff --git a/src/Http/Http.Results/test/AcceptedAtRouteResultTests.cs b/src/Http/Http.Results/test/AcceptedAtRouteResultTests.cs index ae0b8f754085..2c7121d3bd8d 100644 --- a/src/Http/Http.Results/test/AcceptedAtRouteResultTests.cs +++ b/src/Http/Http.Results/test/AcceptedAtRouteResultTests.cs @@ -20,7 +20,7 @@ public void AcceptedAtRouteResult_ProblemDetails_SetsStatusCodeAndValue() { "sample", "route" } }); var obj = new HttpValidationProblemDetails(); - var result = new AcceptedAtRouteHttpResult(routeValues, obj); + var result = new AcceptedAtRouteHttpResult(routeValues: routeValues, value: obj); // Assert Assert.Equal(StatusCodes.Status202Accepted, result.StatusCode); diff --git a/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs b/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs index 5fd0575a3c35..c270e58683a4 100644 --- a/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs +++ b/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs @@ -21,7 +21,7 @@ public void CreatedAtRouteResult_ProblemDetails_SetsStatusCodeAndValue() { "sample", "route" } }); var obj = new HttpValidationProblemDetails(); - var result = new CreatedAtRouteHttpResult(routeValues, obj); + var result = new CreatedAtRouteHttpResult( routeValues: routeValues, value: obj); // Assert Assert.Equal(StatusCodes.Status201Created, result.StatusCode); diff --git a/src/Http/Http.Results/test/LocalRedirectResultTest.cs b/src/Http/Http.Results/test/LocalRedirectResultTest.cs index 33e49752fefd..9e5565757abf 100644 --- a/src/Http/Http.Results/test/LocalRedirectResultTest.cs +++ b/src/Http/Http.Results/test/LocalRedirectResultTest.cs @@ -16,11 +16,12 @@ public void Constructor_WithParameterUrl_SetsResultUrlAndNotPermanentOrPreserveM var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true, false, false); + var result = new RedirectHttpResult(url, false, false, true); // Assert Assert.False(result.PreserveMethod); Assert.False(result.Permanent); + Assert.True(result.AcceptLocalUrlOnly); Assert.Same(url, result.Url); } @@ -31,11 +32,12 @@ public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanentNo var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true, permanent: true, preserveMethod: false); + var result = new RedirectHttpResult(url, true, false, true); // Assert Assert.False(result.PreserveMethod); Assert.True(result.Permanent); + Assert.True(result.AcceptLocalUrlOnly); Assert.Same(url, result.Url); } @@ -46,11 +48,12 @@ public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlPermanentAndPr var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true, permanent: true, preserveMethod: true); + var result = new RedirectHttpResult(url, true, true, true); // Assert Assert.True(result.PreserveMethod); Assert.True(result.Permanent); + Assert.True(result.AcceptLocalUrlOnly); Assert.Same(url, result.Url); } @@ -63,7 +66,7 @@ public async Task Execute_ReturnsExpectedValues() var expectedPath = "/Home/About"; var httpContext = GetHttpContext(appRoot); - var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true, false, false); + var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true); // Act await result.ExecuteAsync(httpContext); @@ -86,7 +89,7 @@ public async Task Execute_Throws_ForNonLocalUrl( { // Arrange var httpContext = GetHttpContext(appRoot); - var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true, false, false); + var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true); // Act & Assert var exception = await Assert.ThrowsAsync(() => result.ExecuteAsync(httpContext)); @@ -107,7 +110,7 @@ public async Task Execute_Throws_ForNonLocalUrlTilde( { // Arrange var httpContext = GetHttpContext(appRoot); - var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true, false, false); + var result = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true); // Act & Assert var exception = await Assert.ThrowsAsync(() => result.ExecuteAsync(httpContext)); diff --git a/src/Http/Http.Results/test/NoContentResultTests.cs b/src/Http/Http.Results/test/NoContentResultTests.cs index 18b56774b6f5..7f997475b979 100644 --- a/src/Http/Http.Results/test/NoContentResultTests.cs +++ b/src/Http/Http.Results/test/NoContentResultTests.cs @@ -13,7 +13,7 @@ public class NoContentResultTests public void NoContentResultTests_InitializesStatusCode() { // Arrange & act - var result = new NoContentHttpResult(); + var result = NoContentHttpResult.Instance; // Assert Assert.Equal(StatusCodes.Status204NoContent, result.StatusCode); @@ -23,7 +23,7 @@ public void NoContentResultTests_InitializesStatusCode() public void NoContentResultTests_ExecuteResultSetsResponseStatusCode() { // Arrange - var result = new NoContentHttpResult(); + var result = NoContentHttpResult.Instance; var httpContext = GetHttpContext(); diff --git a/src/Http/Http.Results/test/RedirectToRouteResultTest.cs b/src/Http/Http.Results/test/RedirectToRouteResultTest.cs index 99dcac7836dc..e1fb58be5e2b 100644 --- a/src/Http/Http.Results/test/RedirectToRouteResultTest.cs +++ b/src/Http/Http.Results/test/RedirectToRouteResultTest.cs @@ -56,7 +56,7 @@ public async Task ExecuteResultAsync_WithFragment_PassesCorrectValuesToRedirect( var expectedStatusCode = StatusCodes.Status301MovedPermanently; var httpContext = GetHttpContext(expectedUrl); - var result = new RedirectToRouteHttpResult("Sample", null, true, "test"); + var result = new RedirectToRouteHttpResult("Sample", null, true, fragment: "test"); // Act await result.ExecuteAsync(httpContext); diff --git a/src/Http/Http.Results/test/UnauthorizedResultTests.cs b/src/Http/Http.Results/test/UnauthorizedResultTests.cs index 50aab7fd7bf9..ce33db419a53 100644 --- a/src/Http/Http.Results/test/UnauthorizedResultTests.cs +++ b/src/Http/Http.Results/test/UnauthorizedResultTests.cs @@ -13,7 +13,7 @@ public class UnauthorizedResultTests public void UnauthorizedResult_InitializesStatusCode() { // Arrange & act - var result = new UnauthorizedHttpResult(); + var result = UnauthorizedHttpResult.Instance; // Assert Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode); @@ -23,7 +23,7 @@ public void UnauthorizedResult_InitializesStatusCode() public void UnauthorizedResult_ExecuteResultSetsResponseStatusCode() { // Arrange - var result = new UnauthorizedHttpResult(); + var result = UnauthorizedHttpResult.Instance; var httpContext = GetHttpContext(); From eecec0a9d8686536feb9e05f9526aa1f83f53cd0 Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Fri, 25 Mar 2022 11:30:25 -0700 Subject: [PATCH 2/6] Public ctors --- .../src/AcceptedAtRouteHttpResult.cs | 5 - .../src/BadRequestObjectHttpResult.cs | 4 +- .../Http.Results/src/ChallengeHttpResult.cs | 12 +- .../src/ConflictObjectHttpResult.cs | 4 +- .../Http.Results/src/ContentHttpResult.cs | 4 +- .../src/CreatedAtRouteHttpResult.cs | 5 - .../Http.Results/src/FileContentHttpResult.cs | 2 +- .../Http.Results/src/FileStreamHttpResult.cs | 2 +- src/Http/Http.Results/src/ForbidHttpResult.cs | 12 +- src/Http/Http.Results/src/JsonHttpResult.cs | 16 ++- .../src/NotFoundObjectHttpResult.cs | 4 +- .../Http.Results/src/OkObjectHttpResult.cs | 5 +- .../src/PhysicalFileHttpResult.cs | 2 +- .../Http.Results/src/ProblemHttpResult.cs | 2 + .../Http.Results/src/PublicAPI.Unshipped.txt | 46 +++----- .../Http.Results/src/PushStreamHttpResult.cs | 2 +- .../Http.Results/src/RedirectHttpResult.cs | 31 +++--- .../src/RedirectToRouteHttpResult.cs | 15 +-- src/Http/Http.Results/src/Results.cs | 105 ++++++++++++------ src/Http/Http.Results/src/SignInHttpResult.cs | 11 +- .../Http.Results/src/SignOutHttpResult.cs | 12 +- .../Http.Results/src/StatusCodeHttpResult.cs | 69 ++++++++++++ .../UnprocessableEntityObjectHttpResult.cs | 10 +- .../Http.Results/src/VirtualFileHttpResult.cs | 2 +- .../Http.Results/test/ChallengeResultTest.cs | 4 +- .../Http.Results/test/ForbidResultTest.cs | 9 +- .../test/LocalRedirectResultTest.cs | 18 ++- .../Http.Results/test/RedirectResultTest.cs | 13 ++- .../test/RedirectToRouteResultTest.cs | 13 ++- .../Http.Results/test/SignInResultTest.cs | 12 +- .../Http.Results/test/SignOutResultTest.cs | 4 +- 31 files changed, 282 insertions(+), 173 deletions(-) diff --git a/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs b/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs index b422cbffb8a7..ebfade39293d 100644 --- a/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs +++ b/src/Http/Http.Results/src/AcceptedAtRouteHttpResult.cs @@ -33,11 +33,6 @@ public AcceptedAtRouteHttpResult( HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of without a , and . - /// - public static AcceptedAtRouteHttpResult Empty { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs index 8f1436074ec3..997fb1c79ead 100644 --- a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs +++ b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs @@ -24,9 +24,9 @@ public BadRequestObjectHttpResult(object? error = null) } /// - /// Gets an instance of without a . + /// Gets an instance of with a null . /// - public static BadRequestObjectHttpResult Empty { get; } = new(); + public static BadRequestObjectHttpResult Instance { get; } = new(); /// /// Gets the object result. diff --git a/src/Http/Http.Results/src/ChallengeHttpResult.cs b/src/Http/Http.Results/src/ChallengeHttpResult.cs index f22600ee26f4..0588438254e9 100644 --- a/src/Http/Http.Results/src/ChallengeHttpResult.cs +++ b/src/Http/Http.Results/src/ChallengeHttpResult.cs @@ -17,7 +17,7 @@ public sealed partial class ChallengeHttpResult : IResult /// Initializes a new instance of with the default sign out scheme. /// public ChallengeHttpResult() - : this(authenticationSchemes: Array.Empty(), properties: null) + : this(properties: null, authenticationSchemes: Array.Empty()) { } @@ -28,7 +28,7 @@ public ChallengeHttpResult() /// used to perform the authentication /// challenge. public ChallengeHttpResult(AuthenticationProperties? properties) - : this(Array.Empty(), properties) + : this(properties, authenticationSchemes: Array.Empty()) { } @@ -39,8 +39,8 @@ public ChallengeHttpResult(AuthenticationProperties? properties) /// The authentication schemes to challenge. /// used to perform the authentication /// challenge. - public ChallengeHttpResult(string authenticationScheme, AuthenticationProperties? properties) - : this(new[] { authenticationScheme }, properties) + public ChallengeHttpResult(AuthenticationProperties? properties, string authenticationScheme) + : this(properties, authenticationSchemes: new[] { authenticationScheme }) { } @@ -51,7 +51,7 @@ public ChallengeHttpResult(string authenticationScheme, AuthenticationProperties /// The authentication scheme to challenge. /// used to perform the authentication /// challenge. - public ChallengeHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + public ChallengeHttpResult(AuthenticationProperties? properties, IList authenticationSchemes) { AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; @@ -60,7 +60,7 @@ public ChallengeHttpResult(IList authenticationSchemes, AuthenticationPr /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; init; } + public IReadOnlyList AuthenticationSchemes { get; } /// /// Gets the used to perform the sign-out operation. diff --git a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs index f7145ad75297..b4ccbb05946d 100644 --- a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs +++ b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs @@ -24,9 +24,9 @@ public ConflictObjectHttpResult(object? error = null) } /// - /// Gets an instance of without a . + /// Gets an instance of with a null . /// - public static ConflictObjectHttpResult Empty { get; } = new(); + public static ConflictObjectHttpResult Instance { get; } = new(); /// /// Gets the object result. diff --git a/src/Http/Http.Results/src/ContentHttpResult.cs b/src/Http/Http.Results/src/ContentHttpResult.cs index f14c2009fc7f..8ac18dace983 100644 --- a/src/Http/Http.Results/src/ContentHttpResult.cs +++ b/src/Http/Http.Results/src/ContentHttpResult.cs @@ -42,12 +42,12 @@ public ContentHttpResult(string content, string contentType) /// /// Gets or set the content representing the body of the response. /// - public string? Content { get; init;} + public string? Content { get; } /// /// Gets or sets the Content-Type header for the response. /// - public string? ContentType { get; init; } + public string? ContentType { get; } /// /// Gets the HTTP status code. diff --git a/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs b/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs index f89c59273720..7ccc35c7e1a3 100644 --- a/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs +++ b/src/Http/Http.Results/src/CreatedAtRouteHttpResult.cs @@ -32,11 +32,6 @@ public CreatedAtRouteHttpResult( HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of without a , and . - /// - public static CreatedAtRouteHttpResult Empty { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/FileContentHttpResult.cs b/src/Http/Http.Results/src/FileContentHttpResult.cs index 426a53a642ae..0af5236a82af 100644 --- a/src/Http/Http.Results/src/FileContentHttpResult.cs +++ b/src/Http/Http.Results/src/FileContentHttpResult.cs @@ -48,7 +48,7 @@ public FileContentHttpResult(ReadOnlyMemory fileContents, string? contentT /// /// Gets the Content-Type header for the response. /// - public string ContentType { get; init; } + public string ContentType { get; } /// /// Gets the value that enables range processing for the file result. diff --git a/src/Http/Http.Results/src/FileStreamHttpResult.cs b/src/Http/Http.Results/src/FileStreamHttpResult.cs index be185c97b951..70d2ab51cef5 100644 --- a/src/Http/Http.Results/src/FileStreamHttpResult.cs +++ b/src/Http/Http.Results/src/FileStreamHttpResult.cs @@ -57,7 +57,7 @@ public FileStreamHttpResult(Stream fileStream, string? contentType) /// /// Gets the Content-Type header for the response. /// - public string ContentType { get; init; } + public string ContentType { get; } /// /// Gets the value that enables range processing for the file result. diff --git a/src/Http/Http.Results/src/ForbidHttpResult.cs b/src/Http/Http.Results/src/ForbidHttpResult.cs index cdf4f888553b..0f8e4b8eff44 100644 --- a/src/Http/Http.Results/src/ForbidHttpResult.cs +++ b/src/Http/Http.Results/src/ForbidHttpResult.cs @@ -17,7 +17,7 @@ public sealed partial class ForbidHttpResult : IResult /// Initializes a new instance of with the default sign out scheme. /// public ForbidHttpResult() - : this(authenticationSchemes: Array.Empty(), properties: null) + : this(properties: null, authenticationSchemes: Array.Empty()) { } @@ -28,7 +28,7 @@ public ForbidHttpResult() /// used to perform the authentication /// challenge. public ForbidHttpResult(AuthenticationProperties? properties) - : this(Array.Empty(), properties) + : this(properties, authenticationSchemes: Array.Empty()) { } @@ -39,8 +39,8 @@ public ForbidHttpResult(AuthenticationProperties? properties) /// The authentication schemes to challenge. /// used to perform the authentication /// challenge. - public ForbidHttpResult(string authenticationScheme, AuthenticationProperties? properties) - : this(new[] { authenticationScheme }, properties) + public ForbidHttpResult(AuthenticationProperties? properties, string authenticationScheme) + : this(properties, authenticationSchemes: new[] { authenticationScheme }) { } @@ -51,7 +51,7 @@ public ForbidHttpResult(string authenticationScheme, AuthenticationProperties? p /// The authentication scheme to challenge. /// used to perform the authentication /// challenge. - public ForbidHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + public ForbidHttpResult(AuthenticationProperties? properties, IList authenticationSchemes) { AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; @@ -60,7 +60,7 @@ public ForbidHttpResult(IList authenticationSchemes, AuthenticationPrope /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; init; } + public IReadOnlyList AuthenticationSchemes { get; } /// /// Gets the used to perform the authentication challenge. diff --git a/src/Http/Http.Results/src/JsonHttpResult.cs b/src/Http/Http.Results/src/JsonHttpResult.cs index ee7de81576a7..10fcac55c003 100644 --- a/src/Http/Http.Results/src/JsonHttpResult.cs +++ b/src/Http/Http.Results/src/JsonHttpResult.cs @@ -12,6 +12,8 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class JsonHttpResult : IResult { + private int? _statusCode; + /// /// Initializes a new instance of the class with the values. /// @@ -31,7 +33,7 @@ public JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOption Value = value; JsonSerializerOptions = jsonSerializerOptions; - HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); + HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, statusCode: null); } /// @@ -42,7 +44,7 @@ public JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOption /// /// Gets or sets the serializer settings. /// - public JsonSerializerOptions? JsonSerializerOptions { get; init; } + public JsonSerializerOptions? JsonSerializerOptions { get; } /// /// Gets the value for the Content-Type header. @@ -52,7 +54,15 @@ public JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOption /// /// Gets the HTTP status code. /// - public int? StatusCode { get; init; } + public int? StatusCode + { + get => _statusCode; + init + { + _statusCode = value; + HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, _statusCode); + } + } /// public Task ExecuteAsync(HttpContext httpContext) diff --git a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs index 2667fe92f182..4a1e0816e444 100644 --- a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs +++ b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs @@ -23,9 +23,9 @@ public NotFoundObjectHttpResult(object? value = null) } /// - /// Gets an instance of without a . + /// Gets an instance of with a null . /// - public static NotFoundObjectHttpResult Empty { get; } = new(); + public static NotFoundObjectHttpResult Instance { get; } = new(); /// /// Gets the object result. diff --git a/src/Http/Http.Results/src/OkObjectHttpResult.cs b/src/Http/Http.Results/src/OkObjectHttpResult.cs index cca6f074f05b..ebd249299cfa 100644 --- a/src/Http/Http.Results/src/OkObjectHttpResult.cs +++ b/src/Http/Http.Results/src/OkObjectHttpResult.cs @@ -24,9 +24,9 @@ public OkObjectHttpResult(object? value = null) } /// - /// Gets an instance of without a . + /// Gets an instance of with a null . /// - public static OkObjectHttpResult Empty { get; } = new(); + public static OkObjectHttpResult Instance { get; } = new(); /// /// Gets the object result. @@ -41,7 +41,6 @@ public OkObjectHttpResult(object? value = null) /// public Task ExecuteAsync(HttpContext httpContext) { - // Creating the logger with a string to preserve the category after the refactoring. var loggerFactory = httpContext.RequestServices.GetRequiredService(); var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.OkObjectResult"); diff --git a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs index e323ecc45b4a..9229393c6644 100644 --- a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs +++ b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs @@ -48,7 +48,7 @@ public PhysicalFileHttpResult(string fileName, string? contentType) /// /// Gets the Content-Type header for the response. /// - public string ContentType { get; init; } + public string ContentType { get; } /// /// Gets the value that enables range processing for the file result. diff --git a/src/Http/Http.Results/src/ProblemHttpResult.cs b/src/Http/Http.Results/src/ProblemHttpResult.cs index ad40be60c971..affb6cf9415f 100644 --- a/src/Http/Http.Results/src/ProblemHttpResult.cs +++ b/src/Http/Http.Results/src/ProblemHttpResult.cs @@ -59,6 +59,8 @@ public ProblemHttpResult( ProblemDetails.Extensions.Add(extension); } } + + HttpResultsHelper.ApplyProblemDetailsDefaults(ProblemDetails, statusCode: null); } /// diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index 3a04ba241428..b8cdff7e6178 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -22,11 +22,10 @@ Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ChallengeHttpResult Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! -Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.init -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult() -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ChallengeHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.ConflictObjectHttpResult @@ -36,12 +35,10 @@ Microsoft.AspNetCore.Http.ConflictObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ContentHttpResult Microsoft.AspNetCore.Http.ContentHttpResult.Content.get -> string? -Microsoft.AspNetCore.Http.ContentHttpResult.Content.init -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult() -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content) -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content, string! contentType) -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentType.get -> string? -Microsoft.AspNetCore.Http.ContentHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.ContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ContentHttpResult.StatusCode.get -> int? Microsoft.AspNetCore.Http.ContentHttpResult.StatusCode.init -> void @@ -65,7 +62,6 @@ Microsoft.AspNetCore.Http.EmptyHttpResult Microsoft.AspNetCore.Http.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.FileContentHttpResult Microsoft.AspNetCore.Http.FileContentHttpResult.ContentType.get -> string! -Microsoft.AspNetCore.Http.FileContentHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.EnableRangeProcessing.get -> bool Microsoft.AspNetCore.Http.FileContentHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? @@ -81,7 +77,6 @@ Microsoft.AspNetCore.Http.FileContentHttpResult.LastModified.get -> System.DateT Microsoft.AspNetCore.Http.FileContentHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult Microsoft.AspNetCore.Http.FileStreamHttpResult.ContentType.get -> string! -Microsoft.AspNetCore.Http.FileStreamHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.EnableRangeProcessing.get -> bool Microsoft.AspNetCore.Http.FileStreamHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? @@ -97,12 +92,11 @@ Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.get -> System.DateTi Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult Microsoft.AspNetCore.Http.ForbidHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! -Microsoft.AspNetCore.Http.ForbidHttpResult.AuthenticationSchemes.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult() -> void Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.ForbidHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.JsonHttpResult Microsoft.AspNetCore.Http.JsonHttpResult.ContentType.get -> string? @@ -111,7 +105,6 @@ Microsoft.AspNetCore.Http.JsonHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http. Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value) -> void Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions) -> void Microsoft.AspNetCore.Http.JsonHttpResult.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions? -Microsoft.AspNetCore.Http.JsonHttpResult.JsonSerializerOptions.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.get -> int? Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.Value.get -> object? @@ -130,7 +123,6 @@ Microsoft.AspNetCore.Http.OkObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.OkObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.PhysicalFileHttpResult Microsoft.AspNetCore.Http.PhysicalFileHttpResult.ContentType.get -> string! -Microsoft.AspNetCore.Http.PhysicalFileHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EnableRangeProcessing.get -> bool Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.PhysicalFileHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? @@ -153,7 +145,6 @@ Microsoft.AspNetCore.Http.ProblemHttpResult.ProblemHttpResult(string? detail = n Microsoft.AspNetCore.Http.ProblemHttpResult.StatusCode.get -> int? Microsoft.AspNetCore.Http.PushStreamHttpResult Microsoft.AspNetCore.Http.PushStreamHttpResult.ContentType.get -> string! -Microsoft.AspNetCore.Http.PushStreamHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.EnableRangeProcessing.get -> bool Microsoft.AspNetCore.Http.PushStreamHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? @@ -169,13 +160,13 @@ Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func< Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback, string? contentType) -> void Microsoft.AspNetCore.Http.RedirectHttpResult Microsoft.AspNetCore.Http.RedirectHttpResult.AcceptLocalUrlOnly.get -> bool -Microsoft.AspNetCore.Http.RedirectHttpResult.AcceptLocalUrlOnly.init -> void Microsoft.AspNetCore.Http.RedirectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.init -> void Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.init -> void -Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url, bool permanent = false, bool preserveMethod = false, bool acceptLocalUrlOnly = false) -> void +Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url) -> void +Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url, bool acceptLocalUrlOnly) -> void Microsoft.AspNetCore.Http.RedirectHttpResult.Url.get -> string! Microsoft.AspNetCore.Http.RedirectToRouteHttpResult Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -187,7 +178,7 @@ Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.init -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(object! routeValues) -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string! routeName) -> void -Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string? routeName, object? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> void +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string? routeName, object? routeValues) -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? Microsoft.AspNetCore.Http.SignInHttpResult @@ -197,16 +188,15 @@ Microsoft.AspNetCore.Http.SignInHttpResult.ExecuteAsync(Microsoft.AspNetCore.Htt Microsoft.AspNetCore.Http.SignInHttpResult.Principal.get -> System.Security.Claims.ClaimsPrincipal! Microsoft.AspNetCore.Http.SignInHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.SignInHttpResult.Properties.init -> void -Microsoft.AspNetCore.Http.SignInHttpResult.SignInHttpResult(System.Security.Claims.ClaimsPrincipal! principal, string? authenticationScheme = null, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null) -> void +Microsoft.AspNetCore.Http.SignInHttpResult.SignInHttpResult(System.Security.Claims.ClaimsPrincipal! principal) -> void Microsoft.AspNetCore.Http.SignOutHttpResult Microsoft.AspNetCore.Http.SignOutHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! -Microsoft.AspNetCore.Http.SignOutHttpResult.AuthenticationSchemes.init -> void Microsoft.AspNetCore.Http.SignOutHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.SignOutHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult() -> void Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(System.Collections.Generic.IList! authenticationSchemes, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(string! authenticationScheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.StatusCodeHttpResult Microsoft.AspNetCore.Http.StatusCodeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.StatusCodeHttpResult.StatusCode.get -> int @@ -217,11 +207,10 @@ Microsoft.AspNetCore.Http.UnauthorizedHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.StatusCode.get -> int -Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.UnprocessableEntityObjectHttpResult(object? value = null) -> void +Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.UnprocessableEntityObjectHttpResult(object? error = null) -> void Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.VirtualFileHttpResult Microsoft.AspNetCore.Http.VirtualFileHttpResult.ContentType.get -> string! -Microsoft.AspNetCore.Http.VirtualFileHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.EnableRangeProcessing.get -> bool Microsoft.AspNetCore.Http.VirtualFileHttpResult.EnableRangeProcessing.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? @@ -235,16 +224,15 @@ Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.get -> System.DateT Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName) -> void Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName, string? contentType) -> void -static Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.Empty.get -> Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult! -static Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.BadRequestObjectHttpResult! -static Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.ConflictObjectHttpResult! -static Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.Empty.get -> Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult! +static Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.BadRequestObjectHttpResult! +static Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.ConflictObjectHttpResult! static Microsoft.AspNetCore.Http.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.EmptyHttpResult! -static Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.NotFoundObjectHttpResult! -static Microsoft.AspNetCore.Http.OkObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.OkObjectHttpResult! +static Microsoft.AspNetCore.Http.NoContentHttpResult.Instance.get -> Microsoft.AspNetCore.Http.NoContentHttpResult! +static Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.NotFoundObjectHttpResult! +static Microsoft.AspNetCore.Http.OkObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.OkObjectHttpResult! static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.UnauthorizedHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnauthorizedHttpResult! -static Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Empty.get -> Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult! +static Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult! diff --git a/src/Http/Http.Results/src/PushStreamHttpResult.cs b/src/Http/Http.Results/src/PushStreamHttpResult.cs index fde14fad3b85..9d6168ef47b9 100644 --- a/src/Http/Http.Results/src/PushStreamHttpResult.cs +++ b/src/Http/Http.Results/src/PushStreamHttpResult.cs @@ -43,7 +43,7 @@ public PushStreamHttpResult(Func streamWriterCallback, string? con /// /// Gets the Content-Type header for the response. /// - public string ContentType { get; init; } + public string ContentType { get; } /// /// Gets the value that enables range processing for the file result. diff --git a/src/Http/Http.Results/src/RedirectHttpResult.cs b/src/Http/Http.Results/src/RedirectHttpResult.cs index d8165be5e3c1..89095a7453b4 100644 --- a/src/Http/Http.Results/src/RedirectHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectHttpResult.cs @@ -18,16 +18,19 @@ public sealed partial class RedirectHttpResult : IResult /// provided. /// /// The URL to redirect to. - /// Specifies whether the redirect should be permanent (301) or temporary (302). - /// If set to true, make the temporary redirect (307) - /// or permanent redirect (308) preserve the initial request method. + public RedirectHttpResult(string url) + : this(url, acceptLocalUrlOnly: false) + { + } + + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The URL to redirect to. /// If set to true, only local URLs are accepted /// and will throw an exception when the supplied URL is not considered local. - public RedirectHttpResult( - string url, - bool permanent = false, - bool preserveMethod = false, - bool acceptLocalUrlOnly = false) + public RedirectHttpResult(string url, bool acceptLocalUrlOnly) { if (url == null) { @@ -40,8 +43,6 @@ public RedirectHttpResult( } Url = url; - Permanent = permanent; - PreserveMethod = preserveMethod; AcceptLocalUrlOnly = acceptLocalUrlOnly; } @@ -50,6 +51,11 @@ public RedirectHttpResult( /// public string Url { get; } + /// + /// Gets an indication that only local URLs are accepted. + /// + public bool AcceptLocalUrlOnly { get; } + /// /// Gets the value that specifies that the redirect should be permanent if true or temporary if false. /// @@ -60,11 +66,6 @@ public RedirectHttpResult( /// public bool PreserveMethod { get; init; } - /// - /// Gets an indication that only local URLs are accepted. - /// - public bool AcceptLocalUrlOnly { get; init; } - /// public Task ExecuteAsync(HttpContext httpContext) { diff --git a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs index 35e533054c5b..45f594c15689 100644 --- a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs @@ -38,23 +38,10 @@ public RedirectToRouteHttpResult(string routeName) /// /// The name of the route. /// The parameters for the route. - /// If set to true, makes the redirect permanent (301). - /// Otherwise a temporary redirect is used (302). - /// If set to true, make the temporary redirect (307) - /// or permanent redirect (308) preserve the initial request method. - /// The fragment to add to the URL. - public RedirectToRouteHttpResult( - string? routeName, - object? routeValues, - bool permanent = false, - bool preserveMethod = false, - string? fragment = null) + public RedirectToRouteHttpResult(string? routeName, object? routeValues) { RouteName = routeName; RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues); - PreserveMethod = preserveMethod; - Permanent = permanent; - Fragment = fragment; } /// diff --git a/src/Http/Http.Results/src/Results.cs b/src/Http/Http.Results/src/Results.cs index 991a7512f675..3490da03dd34 100644 --- a/src/Http/Http.Results/src/Results.cs +++ b/src/Http/Http.Results/src/Results.cs @@ -32,7 +32,9 @@ public static class Results public static IResult Challenge( AuthenticationProperties? properties = null, IList? authenticationSchemes = null) - => new ChallengeHttpResult(authenticationSchemes: authenticationSchemes ?? Array.Empty(), properties); + { + return new ChallengeHttpResult(properties, authenticationSchemes: authenticationSchemes ?? Array.Empty()); + } /// /// Creates a that on execution invokes . @@ -50,7 +52,9 @@ public static IResult Challenge( /// a redirect to show a login page. /// public static IResult Forbid(AuthenticationProperties? properties = null, IList? authenticationSchemes = null) - => new ForbidHttpResult(authenticationSchemes: authenticationSchemes ?? Array.Empty(), properties); + { + return new ForbidHttpResult(properties, authenticationSchemes: authenticationSchemes ?? Array.Empty()); + } /// /// Creates an that on execution invokes . @@ -63,7 +67,13 @@ public static IResult SignIn( ClaimsPrincipal principal, AuthenticationProperties? properties = null, string? authenticationScheme = null) - => new SignInHttpResult(principal, authenticationScheme, properties); + { + return new SignInHttpResult(principal) + { + Properties = properties, + AuthenticationScheme = authenticationScheme, + }; + } /// /// Creates an that on execution invokes . @@ -72,7 +82,7 @@ public static IResult SignIn( /// The authentication scheme to use for the sign-out operation. /// The created for the response. public static IResult SignOut(AuthenticationProperties? properties = null, IList? authenticationSchemes = null) - => new SignOutHttpResult(authenticationSchemes ?? Array.Empty(), properties); + => new SignOutHttpResult(properties, authenticationSchemes ?? Array.Empty()); /// /// Writes the string to the HTTP response. @@ -107,17 +117,15 @@ public static IResult Content(string content, string? contentType = null, Encodi /// public static IResult Text(string content, string? contentType = null, Encoding? contentEncoding = null) { - MediaTypeHeaderValue? mediaTypeHeaderValue = null; if (contentType is not null) { - mediaTypeHeaderValue = MediaTypeHeaderValue.Parse(contentType); + var mediaTypeHeaderValue = MediaTypeHeaderValue.Parse(contentType); mediaTypeHeaderValue.Encoding = contentEncoding ?? mediaTypeHeaderValue.Encoding; + + return new ContentHttpResult(content, mediaTypeHeaderValue.ToString()); } - return new ContentHttpResult(content) - { - ContentType = mediaTypeHeaderValue?.ToString(), - }; + return new ContentHttpResult(content); } /// @@ -157,28 +165,30 @@ public static IResult Json(object? data, JsonSerializerOptions? options = null, /// This API is an alias for . /// /// The file contents. - /// The Content-Type of the file. - /// The suggested file name. - /// Set to true to enable range requests processing. - /// The of when the file was last modified. - /// The associated with the file. + /// The Content-Type of the file. + /// The suggested file name. + /// Set to true to enable range requests processing. + /// The of when the file was last modified. + /// The associated with the file. /// The created for the response. #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static IResult File( #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters - byte[] fileContents, + byte[] fileContents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, DateTimeOffset? lastModified = null, EntityTagHeaderValue? entityTag = null) - => new FileContentHttpResult(fileContents, contentType) + { + return new FileContentHttpResult(fileContents, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, LastModified = lastModified, EntityTag = entityTag, }; + } /// /// Writes the byte-array content to the response. @@ -203,13 +213,15 @@ public static IResult Bytes( bool enableRangeProcessing = false, DateTimeOffset? lastModified = null, EntityTagHeaderValue? entityTag = null) - => new FileContentHttpResult(contents, contentType) + { + return new FileContentHttpResult(contents, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, LastModified = lastModified, EntityTag = entityTag, }; + } /// /// Writes the byte-array content to the response. @@ -234,13 +246,15 @@ public static IResult Bytes( bool enableRangeProcessing = false, DateTimeOffset? lastModified = null, EntityTagHeaderValue? entityTag = null) - => new FileContentHttpResult(contents, contentType) + { + return new FileContentHttpResult(contents, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, LastModified = lastModified, EntityTag = entityTag, }; + } /// /// Writes the specified to the response. @@ -267,7 +281,7 @@ public static IResult Bytes( #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static IResult File( #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters - Stream fileStream, + Stream fileStream, string? contentType = null, string? fileDownloadName = null, DateTimeOffset? lastModified = null, @@ -409,7 +423,7 @@ public static IResult Stream( #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static IResult File( #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters - string path, + string path, string? contentType = null, string? fileDownloadName = null, DateTimeOffset? lastModified = null, @@ -452,7 +466,13 @@ public static IResult File( /// If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the initial request method. /// The created for the response. public static IResult Redirect(string url, bool permanent = false, bool preserveMethod = false) - => new RedirectHttpResult(url, permanent, preserveMethod); + { + return new RedirectHttpResult(url) + { + Permanent = permanent, + PreserveMethod = preserveMethod, + }; + } /// /// Redirects to the specified . @@ -468,7 +488,13 @@ public static IResult Redirect(string url, bool permanent = false, bool preserve /// If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the initial request method. /// The created for the response. public static IResult LocalRedirect(string localUrl, bool permanent = false, bool preserveMethod = false) - => new RedirectHttpResult(localUrl, permanent, preserveMethod, acceptLocalUrlOnly: true); + { + return new RedirectHttpResult(localUrl, acceptLocalUrlOnly: true) + { + Permanent = permanent, + PreserveMethod = preserveMethod, + }; + } /// /// Redirects to the specified route. @@ -486,12 +512,14 @@ public static IResult LocalRedirect(string localUrl, bool permanent = false, boo /// The fragment to add to the URL. /// The created for the response. public static IResult RedirectToRoute(string? routeName = null, object? routeValues = null, bool permanent = false, bool preserveMethod = false, string? fragment = null) - => new RedirectToRouteHttpResult( - routeName: routeName, - routeValues: routeValues, - permanent: permanent, - preserveMethod: preserveMethod, - fragment: fragment); + { + return new RedirectToRouteHttpResult(routeName, routeValues) + { + Fragment = fragment, + Permanent = permanent, + PreserveMethod = preserveMethod, + }; + } /// /// Creates a object by specifying a . @@ -499,7 +527,14 @@ public static IResult RedirectToRoute(string? routeName = null, object? routeVal /// The status code to set on the response. /// The created object for the response. public static IResult StatusCode(int statusCode) - => new StatusCodeHttpResult(statusCode); + { + if (StatusCodeHttpResult.KnownStatusCodes.TryGetValue(statusCode, out var result)) + { + return result; + } + + return new StatusCodeHttpResult(statusCode); + } /// /// Produces a response. @@ -507,7 +542,7 @@ public static IResult StatusCode(int statusCode) /// The value to be included in the HTTP response body. /// The created for the response. public static IResult NotFound(object? value = null) - => value is null ? NotFoundObjectHttpResult.Empty : new NotFoundObjectHttpResult(value); + => value is null ? NotFoundObjectHttpResult.Instance : new NotFoundObjectHttpResult(value); /// /// Produces a response. @@ -522,7 +557,7 @@ public static IResult Unauthorized() /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult BadRequest(object? error = null) - => error is null ? BadRequestObjectHttpResult.Empty : new BadRequestObjectHttpResult(error); + => error is null ? BadRequestObjectHttpResult.Instance : new BadRequestObjectHttpResult(error); /// /// Produces a response. @@ -530,7 +565,7 @@ public static IResult BadRequest(object? error = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult Conflict(object? error = null) - => error is null ? ConflictObjectHttpResult.Empty : new ConflictObjectHttpResult(error); + => error is null ? ConflictObjectHttpResult.Instance : new ConflictObjectHttpResult(error); /// /// Produces a response. @@ -545,7 +580,7 @@ public static IResult NoContent() /// The value to be included in the HTTP response body. /// The created for the response. public static IResult Ok(object? value = null) - => value is null ? OkObjectHttpResult.Empty : new OkObjectHttpResult(value); + => value is null ? OkObjectHttpResult.Instance : new OkObjectHttpResult(value); /// /// Produces a response. @@ -553,7 +588,7 @@ public static IResult Ok(object? value = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult UnprocessableEntity(object? error = null) - => error is null ? UnprocessableEntityObjectHttpResult.Empty : new UnprocessableEntityObjectHttpResult(error); + => error is null ? UnprocessableEntityObjectHttpResult.Instance : new UnprocessableEntityObjectHttpResult(error); /// /// Produces a response. diff --git a/src/Http/Http.Results/src/SignInHttpResult.cs b/src/Http/Http.Results/src/SignInHttpResult.cs index 1fc2a6aa0b20..b8224cb1d079 100644 --- a/src/Http/Http.Results/src/SignInHttpResult.cs +++ b/src/Http/Http.Results/src/SignInHttpResult.cs @@ -15,19 +15,12 @@ public sealed partial class SignInHttpResult : IResult { /// /// Initializes a new instance of with the - /// specified authentication scheme and . + /// specified principal. /// /// The claims principal containing the user claims. - /// The authentication schemes to use when signing in the user. - /// used to perform the sign-in operation. - public SignInHttpResult( - ClaimsPrincipal principal, - string? authenticationScheme = null, - AuthenticationProperties? properties = null) + public SignInHttpResult(ClaimsPrincipal principal) { Principal = principal ?? throw new ArgumentNullException(nameof(principal)); - AuthenticationScheme = authenticationScheme; - Properties = properties; } /// diff --git a/src/Http/Http.Results/src/SignOutHttpResult.cs b/src/Http/Http.Results/src/SignOutHttpResult.cs index da7f05f97e50..ca199cef27f5 100644 --- a/src/Http/Http.Results/src/SignOutHttpResult.cs +++ b/src/Http/Http.Results/src/SignOutHttpResult.cs @@ -17,7 +17,7 @@ public sealed partial class SignOutHttpResult : IResult /// Initializes a new instance of with the default sign out scheme. /// public SignOutHttpResult() - : this(authenticationSchemes: Array.Empty(), properties: null) + : this(properties: null, authenticationSchemes: Array.Empty()) { } @@ -28,7 +28,7 @@ public SignOutHttpResult() /// used to perform the authentication /// challenge. public SignOutHttpResult(AuthenticationProperties? properties) - : this(Array.Empty(), properties) + : this(properties, authenticationSchemes: Array.Empty()) { } @@ -39,8 +39,8 @@ public SignOutHttpResult(AuthenticationProperties? properties) /// The authentication schemes to challenge. /// used to perform the authentication /// challenge. - public SignOutHttpResult(string authenticationScheme, AuthenticationProperties? properties) - : this(new[] { authenticationScheme }, properties) + public SignOutHttpResult(AuthenticationProperties? properties, string authenticationScheme) + : this(properties, authenticationSchemes: new[] { authenticationScheme }) { } @@ -51,7 +51,7 @@ public SignOutHttpResult(string authenticationScheme, AuthenticationProperties? /// The authentication scheme to challenge. /// used to perform the authentication /// challenge. - public SignOutHttpResult(IList authenticationSchemes, AuthenticationProperties? properties) + public SignOutHttpResult(AuthenticationProperties? properties, IList authenticationSchemes) { AuthenticationSchemes = authenticationSchemes.AsReadOnly(); Properties = properties; @@ -60,7 +60,7 @@ public SignOutHttpResult(IList authenticationSchemes, AuthenticationProp /// /// Gets the authentication schemes that are challenged. /// - public IReadOnlyList AuthenticationSchemes { get; init; } + public IReadOnlyList AuthenticationSchemes { get; } /// /// Gets the used to perform the sign-out operation. diff --git a/src/Http/Http.Results/src/StatusCodeHttpResult.cs b/src/Http/Http.Results/src/StatusCodeHttpResult.cs index a6422912b6ef..5c9c049a99e0 100644 --- a/src/Http/Http.Results/src/StatusCodeHttpResult.cs +++ b/src/Http/Http.Results/src/StatusCodeHttpResult.cs @@ -12,6 +12,75 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class StatusCodeHttpResult : IResult { + internal static readonly IReadOnlyDictionary KnownStatusCodes = new Dictionary + { + [StatusCodes.Status100Continue] = new StatusCodeHttpResult(StatusCodes.Status100Continue), + [StatusCodes.Status101SwitchingProtocols] = new StatusCodeHttpResult(StatusCodes.Status101SwitchingProtocols), + [StatusCodes.Status102Processing] = new StatusCodeHttpResult(StatusCodes.Status102Processing), + [StatusCodes.Status200OK] = new StatusCodeHttpResult(StatusCodes.Status200OK), + [StatusCodes.Status201Created] = new StatusCodeHttpResult(StatusCodes.Status201Created), + [StatusCodes.Status202Accepted] = new StatusCodeHttpResult(StatusCodes.Status202Accepted), + [StatusCodes.Status203NonAuthoritative] = new StatusCodeHttpResult(StatusCodes.Status203NonAuthoritative), + [StatusCodes.Status204NoContent] = new StatusCodeHttpResult(StatusCodes.Status204NoContent), + [StatusCodes.Status205ResetContent] = new StatusCodeHttpResult(StatusCodes.Status205ResetContent), + [StatusCodes.Status206PartialContent] = new StatusCodeHttpResult(StatusCodes.Status206PartialContent), + [StatusCodes.Status207MultiStatus] = new StatusCodeHttpResult(StatusCodes.Status207MultiStatus), + [StatusCodes.Status208AlreadyReported] = new StatusCodeHttpResult(StatusCodes.Status208AlreadyReported), + [StatusCodes.Status226IMUsed] = new StatusCodeHttpResult(StatusCodes.Status226IMUsed), + [StatusCodes.Status300MultipleChoices] = new StatusCodeHttpResult(StatusCodes.Status300MultipleChoices), + [StatusCodes.Status301MovedPermanently] = new StatusCodeHttpResult(StatusCodes.Status301MovedPermanently), + [StatusCodes.Status302Found] = new StatusCodeHttpResult(StatusCodes.Status302Found), + [StatusCodes.Status303SeeOther] = new StatusCodeHttpResult(StatusCodes.Status303SeeOther), + [StatusCodes.Status304NotModified] = new StatusCodeHttpResult(StatusCodes.Status304NotModified), + [StatusCodes.Status305UseProxy] = new StatusCodeHttpResult(StatusCodes.Status305UseProxy), + [StatusCodes.Status306SwitchProxy] = new StatusCodeHttpResult(StatusCodes.Status306SwitchProxy), + [StatusCodes.Status307TemporaryRedirect] = new StatusCodeHttpResult(StatusCodes.Status307TemporaryRedirect), + [StatusCodes.Status308PermanentRedirect] = new StatusCodeHttpResult(StatusCodes.Status308PermanentRedirect), + [StatusCodes.Status400BadRequest] = new StatusCodeHttpResult(StatusCodes.Status400BadRequest), + [StatusCodes.Status401Unauthorized] = new StatusCodeHttpResult(StatusCodes.Status401Unauthorized), + [StatusCodes.Status402PaymentRequired] = new StatusCodeHttpResult(StatusCodes.Status402PaymentRequired), + [StatusCodes.Status403Forbidden] = new StatusCodeHttpResult(StatusCodes.Status403Forbidden), + [StatusCodes.Status404NotFound] = new StatusCodeHttpResult(StatusCodes.Status404NotFound), + [StatusCodes.Status405MethodNotAllowed] = new StatusCodeHttpResult(StatusCodes.Status405MethodNotAllowed), + [StatusCodes.Status406NotAcceptable] = new StatusCodeHttpResult(StatusCodes.Status406NotAcceptable), + [StatusCodes.Status407ProxyAuthenticationRequired] = new StatusCodeHttpResult(StatusCodes.Status407ProxyAuthenticationRequired), + [StatusCodes.Status408RequestTimeout] = new StatusCodeHttpResult(StatusCodes.Status408RequestTimeout), + [StatusCodes.Status409Conflict] = new StatusCodeHttpResult(StatusCodes.Status409Conflict), + [StatusCodes.Status410Gone] = new StatusCodeHttpResult(StatusCodes.Status410Gone), + [StatusCodes.Status411LengthRequired] = new StatusCodeHttpResult(StatusCodes.Status411LengthRequired), + [StatusCodes.Status412PreconditionFailed] = new StatusCodeHttpResult(StatusCodes.Status412PreconditionFailed), + [StatusCodes.Status413RequestEntityTooLarge] = new StatusCodeHttpResult(StatusCodes.Status413RequestEntityTooLarge), + [StatusCodes.Status413PayloadTooLarge] = new StatusCodeHttpResult(StatusCodes.Status413PayloadTooLarge), + [StatusCodes.Status414RequestUriTooLong] = new StatusCodeHttpResult(StatusCodes.Status414RequestUriTooLong), + [StatusCodes.Status414UriTooLong] = new StatusCodeHttpResult(StatusCodes.Status414UriTooLong), + [StatusCodes.Status415UnsupportedMediaType] = new StatusCodeHttpResult(StatusCodes.Status415UnsupportedMediaType), + [StatusCodes.Status416RequestedRangeNotSatisfiable] = new StatusCodeHttpResult(StatusCodes.Status416RequestedRangeNotSatisfiable), + [StatusCodes.Status416RangeNotSatisfiable] = new StatusCodeHttpResult(StatusCodes.Status416RangeNotSatisfiable), + [StatusCodes.Status417ExpectationFailed] = new StatusCodeHttpResult(StatusCodes.Status417ExpectationFailed), + [StatusCodes.Status418ImATeapot] = new StatusCodeHttpResult(StatusCodes.Status418ImATeapot), + [StatusCodes.Status419AuthenticationTimeout] = new StatusCodeHttpResult(StatusCodes.Status419AuthenticationTimeout), + [StatusCodes.Status421MisdirectedRequest] = new StatusCodeHttpResult(StatusCodes.Status421MisdirectedRequest), + [StatusCodes.Status422UnprocessableEntity] = new StatusCodeHttpResult(StatusCodes.Status422UnprocessableEntity), + [StatusCodes.Status423Locked] = new StatusCodeHttpResult(StatusCodes.Status423Locked), + [StatusCodes.Status424FailedDependency] = new StatusCodeHttpResult(StatusCodes.Status424FailedDependency), + [StatusCodes.Status426UpgradeRequired] = new StatusCodeHttpResult(StatusCodes.Status426UpgradeRequired), + [StatusCodes.Status428PreconditionRequired] = new StatusCodeHttpResult(StatusCodes.Status428PreconditionRequired), + [StatusCodes.Status429TooManyRequests] = new StatusCodeHttpResult(StatusCodes.Status429TooManyRequests), + [StatusCodes.Status431RequestHeaderFieldsTooLarge] = new StatusCodeHttpResult(StatusCodes.Status431RequestHeaderFieldsTooLarge), + [StatusCodes.Status451UnavailableForLegalReasons] = new StatusCodeHttpResult(StatusCodes.Status451UnavailableForLegalReasons), + [StatusCodes.Status500InternalServerError] = new StatusCodeHttpResult(StatusCodes.Status500InternalServerError), + [StatusCodes.Status501NotImplemented] = new StatusCodeHttpResult(StatusCodes.Status501NotImplemented), + [StatusCodes.Status502BadGateway] = new StatusCodeHttpResult(StatusCodes.Status502BadGateway), + [StatusCodes.Status503ServiceUnavailable] = new StatusCodeHttpResult(StatusCodes.Status503ServiceUnavailable), + [StatusCodes.Status504GatewayTimeout] = new StatusCodeHttpResult(StatusCodes.Status504GatewayTimeout), + [StatusCodes.Status505HttpVersionNotsupported] = new StatusCodeHttpResult(StatusCodes.Status505HttpVersionNotsupported), + [StatusCodes.Status506VariantAlsoNegotiates] = new StatusCodeHttpResult(StatusCodes.Status506VariantAlsoNegotiates), + [StatusCodes.Status507InsufficientStorage] = new StatusCodeHttpResult(StatusCodes.Status507InsufficientStorage), + [StatusCodes.Status508LoopDetected] = new StatusCodeHttpResult(StatusCodes.Status508LoopDetected), + [StatusCodes.Status510NotExtended] = new StatusCodeHttpResult(StatusCodes.Status510NotExtended), + [StatusCodes.Status511NetworkAuthenticationRequired] = new StatusCodeHttpResult(StatusCodes.Status511NetworkAuthenticationRequired), + }; + /// /// Initializes a new instance of the class /// with the given . diff --git a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs index 4fd2ab7eea0c..5bfae9fa96ab 100644 --- a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs +++ b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs @@ -16,17 +16,17 @@ public sealed class UnprocessableEntityObjectHttpResult : IResult /// Initializes a new instance of the class with the values /// provided. /// - /// The value to format in the entity body. - public UnprocessableEntityObjectHttpResult(object? value = null) + /// The value to format in the entity body. + public UnprocessableEntityObjectHttpResult(object? error = null) { - Value = value; + Value = error; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } /// - /// Gets an instance of without a . + /// Gets an instance of with a null . /// - public static UnprocessableEntityObjectHttpResult Empty { get; } = new(); + public static UnprocessableEntityObjectHttpResult Instance { get; } = new(); /// public object? Value { get; internal init; } diff --git a/src/Http/Http.Results/src/VirtualFileHttpResult.cs b/src/Http/Http.Results/src/VirtualFileHttpResult.cs index d3670e1e022b..453964ab8ed3 100644 --- a/src/Http/Http.Results/src/VirtualFileHttpResult.cs +++ b/src/Http/Http.Results/src/VirtualFileHttpResult.cs @@ -50,7 +50,7 @@ public VirtualFileHttpResult(string fileName, string? contentType) /// /// Gets the Content-Type header for the response. /// - public string ContentType { get; init; } + public string ContentType { get; } /// /// Gets the value that enables range processing for the file result. diff --git a/src/Http/Http.Results/test/ChallengeResultTest.cs b/src/Http/Http.Results/test/ChallengeResultTest.cs index 95817e6ba449..658762ce5738 100644 --- a/src/Http/Http.Results/test/ChallengeResultTest.cs +++ b/src/Http/Http.Results/test/ChallengeResultTest.cs @@ -15,7 +15,7 @@ public class ChallengeResultTest public async Task ChallengeResult_ExecuteAsync() { // Arrange - var result = new ChallengeHttpResult("", null); + var result = new ChallengeHttpResult(null, ""); var auth = new Mock(); var httpContext = GetHttpContext(auth); @@ -30,7 +30,7 @@ public async Task ChallengeResult_ExecuteAsync() public async Task ChallengeResult_ExecuteAsync_NoSchemes() { // Arrange - var result = new ChallengeHttpResult(new string[] { }, null); + var result = new ChallengeHttpResult(null, new string[] { }); var auth = new Mock(); var httpContext = GetHttpContext(auth); diff --git a/src/Http/Http.Results/test/ForbidResultTest.cs b/src/Http/Http.Results/test/ForbidResultTest.cs index d3b770178ded..0a76ede38509 100644 --- a/src/Http/Http.Results/test/ForbidResultTest.cs +++ b/src/Http/Http.Results/test/ForbidResultTest.cs @@ -22,7 +22,7 @@ public async Task ExecuteResultAsync_InvokesForbidAsyncOnAuthenticationService() .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new ForbidHttpResult("", null); + var result = new ForbidHttpResult(null, ""); // Act await result.ExecuteAsync(httpContext); @@ -46,7 +46,7 @@ public async Task ExecuteResultAsync_InvokesForbidAsyncOnAllConfiguredSchemes() .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new ForbidHttpResult(new[] { "Scheme1", "Scheme2" }, authProperties); + var result = new ForbidHttpResult(authProperties, new[] { "Scheme1", "Scheme2" }); var routeData = new RouteData(); // Act @@ -95,10 +95,7 @@ public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties_WhenAu .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new ForbidHttpResult(expected) - { - AuthenticationSchemes = new string[0] - }; + var result = new ForbidHttpResult(expected, new string[0]); var routeData = new RouteData(); // Act diff --git a/src/Http/Http.Results/test/LocalRedirectResultTest.cs b/src/Http/Http.Results/test/LocalRedirectResultTest.cs index 9e5565757abf..efaf74b0f0d1 100644 --- a/src/Http/Http.Results/test/LocalRedirectResultTest.cs +++ b/src/Http/Http.Results/test/LocalRedirectResultTest.cs @@ -16,7 +16,11 @@ public void Constructor_WithParameterUrl_SetsResultUrlAndNotPermanentOrPreserveM var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, false, false, true); + var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true) + { + Permanent = false, + PreserveMethod = false + }; // Assert Assert.False(result.PreserveMethod); @@ -32,7 +36,11 @@ public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanentNo var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, true, false, true); + var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true) + { + Permanent = true, + PreserveMethod = false + }; // Assert Assert.False(result.PreserveMethod); @@ -48,7 +56,11 @@ public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlPermanentAndPr var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, true, true, true); + var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true) + { + Permanent = true, + PreserveMethod = true + }; // Assert Assert.True(result.PreserveMethod); diff --git a/src/Http/Http.Results/test/RedirectResultTest.cs b/src/Http/Http.Results/test/RedirectResultTest.cs index 207e6c6850b9..e985c776048e 100644 --- a/src/Http/Http.Results/test/RedirectResultTest.cs +++ b/src/Http/Http.Results/test/RedirectResultTest.cs @@ -14,7 +14,11 @@ public void RedirectResult_Constructor_WithParameterUrlPermanentAndPreservesMeth var url = "/test/url"; // Act - var result = new RedirectHttpResult(url, permanent: true, preserveMethod: true); + var result = new RedirectHttpResult(url) + { + Permanent = true, + PreserveMethod = true, + }; // Assert Assert.True(result.PreserveMethod); @@ -24,7 +28,12 @@ public void RedirectResult_Constructor_WithParameterUrlPermanentAndPreservesMeth protected override Task ExecuteAsync(HttpContext httpContext, string contentPath) { - var redirectResult = new RedirectHttpResult(contentPath, false, false); + var redirectResult = new RedirectHttpResult(contentPath) + { + Permanent = false, + PreserveMethod = false, + }; + return redirectResult.ExecuteAsync(httpContext); } } diff --git a/src/Http/Http.Results/test/RedirectToRouteResultTest.cs b/src/Http/Http.Results/test/RedirectToRouteResultTest.cs index e1fb58be5e2b..c18f62924012 100644 --- a/src/Http/Http.Results/test/RedirectToRouteResultTest.cs +++ b/src/Http/Http.Results/test/RedirectToRouteResultTest.cs @@ -56,7 +56,11 @@ public async Task ExecuteResultAsync_WithFragment_PassesCorrectValuesToRedirect( var expectedStatusCode = StatusCodes.Status301MovedPermanently; var httpContext = GetHttpContext(expectedUrl); - var result = new RedirectToRouteHttpResult("Sample", null, true, fragment: "test"); + var result = new RedirectToRouteHttpResult("Sample", null) + { + Permanent = true, + Fragment = "test", + }; // Act await result.ExecuteAsync(httpContext); @@ -74,7 +78,12 @@ public async Task ExecuteResultAsync_WithFragment_PassesCorrectValuesToRedirect_ var expectedStatusCode = StatusCodes.Status308PermanentRedirect; var httpContext = GetHttpContext(expectedUrl); - var result = new RedirectToRouteHttpResult("Sample", null, true, true, "test"); + var result = new RedirectToRouteHttpResult("Sample", null) + { + Permanent = true, + PreserveMethod = true, + Fragment = "test", + }; // Act await result.ExecuteAsync(httpContext); diff --git a/src/Http/Http.Results/test/SignInResultTest.cs b/src/Http/Http.Results/test/SignInResultTest.cs index 6aef97223c54..4e9358b5c589 100644 --- a/src/Http/Http.Results/test/SignInResultTest.cs +++ b/src/Http/Http.Results/test/SignInResultTest.cs @@ -24,7 +24,11 @@ public async Task ExecuteAsync_InvokesSignInAsyncOnAuthenticationManager() .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new SignInHttpResult(principal, "", null); + var result = new SignInHttpResult(principal) + { + AuthenticationScheme = "", + Properties = null, + }; // Act await result.ExecuteAsync(httpContext); @@ -65,7 +69,11 @@ public async Task ExecuteAsync_InvokesSignInAsyncOnConfiguredScheme() .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new SignInHttpResult(principal, "Scheme1", authProperties); + var result = new SignInHttpResult(principal) + { + AuthenticationScheme = "Scheme1", + Properties = authProperties, + }; // Act await result.ExecuteAsync(httpContext); diff --git a/src/Http/Http.Results/test/SignOutResultTest.cs b/src/Http/Http.Results/test/SignOutResultTest.cs index d3cfa5073659..6f4b6a20d91a 100644 --- a/src/Http/Http.Results/test/SignOutResultTest.cs +++ b/src/Http/Http.Results/test/SignOutResultTest.cs @@ -40,7 +40,7 @@ public async Task ExecuteAsync_InvokesSignOutAsyncOnAuthenticationManager() .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new SignOutHttpResult("", null); + var result = new SignOutHttpResult(null, ""); // Act await result.ExecuteAsync(httpContext); @@ -64,7 +64,7 @@ public async Task ExecuteAsync_InvokesSignOutAsyncOnAllConfiguredSchemes() .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); - var result = new SignOutHttpResult(new[] { "Scheme1", "Scheme2" }, authProperties); + var result = new SignOutHttpResult(authProperties, new[] { "Scheme1", "Scheme2" }); // Act await result.ExecuteAsync(httpContext); From ae7bc35d4562fd45df1e7f59e1503ecfbff19d2e Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Tue, 29 Mar 2022 13:04:05 -0700 Subject: [PATCH 3/6] Caching known results --- src/Http/Http.Results/src/Results.cs | 27 ++-- .../src/ResultsCache.StatusCodes.cs | 144 ++++++++++++++++++ .../src/ResultsCache.StatusCodes.tt | 98 ++++++++++++ src/Http/Http.Results/src/ResultsCache.cs | 15 ++ 4 files changed, 267 insertions(+), 17 deletions(-) create mode 100644 src/Http/Http.Results/src/ResultsCache.StatusCodes.cs create mode 100644 src/Http/Http.Results/src/ResultsCache.StatusCodes.tt create mode 100644 src/Http/Http.Results/src/ResultsCache.cs diff --git a/src/Http/Http.Results/src/Results.cs b/src/Http/Http.Results/src/Results.cs index 3490da03dd34..98d3c265bbda 100644 --- a/src/Http/Http.Results/src/Results.cs +++ b/src/Http/Http.Results/src/Results.cs @@ -33,7 +33,7 @@ public static IResult Challenge( AuthenticationProperties? properties = null, IList? authenticationSchemes = null) { - return new ChallengeHttpResult(properties, authenticationSchemes: authenticationSchemes ?? Array.Empty()); + return new ChallengeHttpResult(properties, authenticationSchemes ?? Array.Empty()); } /// @@ -527,14 +527,7 @@ public static IResult RedirectToRoute(string? routeName = null, object? routeVal /// The status code to set on the response. /// The created object for the response. public static IResult StatusCode(int statusCode) - { - if (StatusCodeHttpResult.KnownStatusCodes.TryGetValue(statusCode, out var result)) - { - return result; - } - - return new StatusCodeHttpResult(statusCode); - } + => ResultsCache.StatusCode(statusCode); /// /// Produces a response. @@ -542,14 +535,14 @@ public static IResult StatusCode(int statusCode) /// The value to be included in the HTTP response body. /// The created for the response. public static IResult NotFound(object? value = null) - => value is null ? NotFoundObjectHttpResult.Instance : new NotFoundObjectHttpResult(value); + => value is null ? ResultsCache.NotFound : new NotFoundObjectHttpResult(value); /// /// Produces a response. /// /// The created for the response. public static IResult Unauthorized() - => UnauthorizedHttpResult.Instance; + => ResultsCache.Unauthorized; /// /// Produces a response. @@ -557,7 +550,7 @@ public static IResult Unauthorized() /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult BadRequest(object? error = null) - => error is null ? BadRequestObjectHttpResult.Instance : new BadRequestObjectHttpResult(error); + => error is null ? ResultsCache.BadRequest : new BadRequestObjectHttpResult(error); /// /// Produces a response. @@ -565,14 +558,14 @@ public static IResult BadRequest(object? error = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult Conflict(object? error = null) - => error is null ? ConflictObjectHttpResult.Instance : new ConflictObjectHttpResult(error); + => error is null ? ResultsCache.Conflict : new ConflictObjectHttpResult(error); /// /// Produces a response. /// /// The created for the response. public static IResult NoContent() - => NoContentHttpResult.Instance; + => ResultsCache.NoContent; /// /// Produces a response. @@ -580,7 +573,7 @@ public static IResult NoContent() /// The value to be included in the HTTP response body. /// The created for the response. public static IResult Ok(object? value = null) - => value is null ? OkObjectHttpResult.Instance : new OkObjectHttpResult(value); + => value is null ? ResultsCache.Ok : new OkObjectHttpResult(value); /// /// Produces a response. @@ -588,7 +581,7 @@ public static IResult Ok(object? value = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult UnprocessableEntity(object? error = null) - => error is null ? UnprocessableEntityObjectHttpResult.Instance : new UnprocessableEntityObjectHttpResult(error); + => error is null ? ResultsCache.UnprocessableEntity : new UnprocessableEntityObjectHttpResult(error); /// /// Produces a response. @@ -727,7 +720,7 @@ public static IResult AcceptedAtRoute(string? routeName = null, object? routeVal /// /// Produces an empty result response, that when executed will do nothing. /// - public static IResult Empty { get; } = EmptyHttpResult.Instance; + public static IResult Empty { get; } = new EmptyHttpResult(); /// /// Provides a container for external libraries to extend diff --git a/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs b/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs new file mode 100644 index 000000000000..02045accc4b0 --- /dev/null +++ b/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs @@ -0,0 +1,144 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +namespace Microsoft.AspNetCore.Http; + +using System.CodeDom.Compiler; + +[GeneratedCode("TextTemplatingFileGenerator", "")] +internal static partial class ResultsCache +{ + private static readonly StatusCodeHttpResult Status100Continue = new StatusCodeHttpResult(StatusCodes.Status100Continue); + private static readonly StatusCodeHttpResult Status101SwitchingProtocols = new StatusCodeHttpResult(StatusCodes.Status101SwitchingProtocols); + private static readonly StatusCodeHttpResult Status102Processing = new StatusCodeHttpResult(StatusCodes.Status102Processing); + private static readonly StatusCodeHttpResult Status200OK = new StatusCodeHttpResult(StatusCodes.Status200OK); + private static readonly StatusCodeHttpResult Status201Created = new StatusCodeHttpResult(StatusCodes.Status201Created); + private static readonly StatusCodeHttpResult Status202Accepted = new StatusCodeHttpResult(StatusCodes.Status202Accepted); + private static readonly StatusCodeHttpResult Status203NonAuthoritative = new StatusCodeHttpResult(StatusCodes.Status203NonAuthoritative); + private static readonly StatusCodeHttpResult Status204NoContent = new StatusCodeHttpResult(StatusCodes.Status204NoContent); + private static readonly StatusCodeHttpResult Status205ResetContent = new StatusCodeHttpResult(StatusCodes.Status205ResetContent); + private static readonly StatusCodeHttpResult Status206PartialContent = new StatusCodeHttpResult(StatusCodes.Status206PartialContent); + private static readonly StatusCodeHttpResult Status207MultiStatus = new StatusCodeHttpResult(StatusCodes.Status207MultiStatus); + private static readonly StatusCodeHttpResult Status208AlreadyReported = new StatusCodeHttpResult(StatusCodes.Status208AlreadyReported); + private static readonly StatusCodeHttpResult Status226IMUsed = new StatusCodeHttpResult(StatusCodes.Status226IMUsed); + private static readonly StatusCodeHttpResult Status300MultipleChoices = new StatusCodeHttpResult(StatusCodes.Status300MultipleChoices); + private static readonly StatusCodeHttpResult Status301MovedPermanently = new StatusCodeHttpResult(StatusCodes.Status301MovedPermanently); + private static readonly StatusCodeHttpResult Status302Found = new StatusCodeHttpResult(StatusCodes.Status302Found); + private static readonly StatusCodeHttpResult Status303SeeOther = new StatusCodeHttpResult(StatusCodes.Status303SeeOther); + private static readonly StatusCodeHttpResult Status304NotModified = new StatusCodeHttpResult(StatusCodes.Status304NotModified); + private static readonly StatusCodeHttpResult Status305UseProxy = new StatusCodeHttpResult(StatusCodes.Status305UseProxy); + private static readonly StatusCodeHttpResult Status306SwitchProxy = new StatusCodeHttpResult(StatusCodes.Status306SwitchProxy); + private static readonly StatusCodeHttpResult Status307TemporaryRedirect = new StatusCodeHttpResult(StatusCodes.Status307TemporaryRedirect); + private static readonly StatusCodeHttpResult Status308PermanentRedirect = new StatusCodeHttpResult(StatusCodes.Status308PermanentRedirect); + private static readonly StatusCodeHttpResult Status400BadRequest = new StatusCodeHttpResult(StatusCodes.Status400BadRequest); + private static readonly StatusCodeHttpResult Status401Unauthorized = new StatusCodeHttpResult(StatusCodes.Status401Unauthorized); + private static readonly StatusCodeHttpResult Status402PaymentRequired = new StatusCodeHttpResult(StatusCodes.Status402PaymentRequired); + private static readonly StatusCodeHttpResult Status403Forbidden = new StatusCodeHttpResult(StatusCodes.Status403Forbidden); + private static readonly StatusCodeHttpResult Status404NotFound = new StatusCodeHttpResult(StatusCodes.Status404NotFound); + private static readonly StatusCodeHttpResult Status405MethodNotAllowed = new StatusCodeHttpResult(StatusCodes.Status405MethodNotAllowed); + private static readonly StatusCodeHttpResult Status406NotAcceptable = new StatusCodeHttpResult(StatusCodes.Status406NotAcceptable); + private static readonly StatusCodeHttpResult Status407ProxyAuthenticationRequired = new StatusCodeHttpResult(StatusCodes.Status407ProxyAuthenticationRequired); + private static readonly StatusCodeHttpResult Status408RequestTimeout = new StatusCodeHttpResult(StatusCodes.Status408RequestTimeout); + private static readonly StatusCodeHttpResult Status409Conflict = new StatusCodeHttpResult(StatusCodes.Status409Conflict); + private static readonly StatusCodeHttpResult Status410Gone = new StatusCodeHttpResult(StatusCodes.Status410Gone); + private static readonly StatusCodeHttpResult Status411LengthRequired = new StatusCodeHttpResult(StatusCodes.Status411LengthRequired); + private static readonly StatusCodeHttpResult Status412PreconditionFailed = new StatusCodeHttpResult(StatusCodes.Status412PreconditionFailed); + private static readonly StatusCodeHttpResult Status413RequestEntityTooLarge = new StatusCodeHttpResult(StatusCodes.Status413RequestEntityTooLarge); + private static readonly StatusCodeHttpResult Status414RequestUriTooLong = new StatusCodeHttpResult(StatusCodes.Status414RequestUriTooLong); + private static readonly StatusCodeHttpResult Status415UnsupportedMediaType = new StatusCodeHttpResult(StatusCodes.Status415UnsupportedMediaType); + private static readonly StatusCodeHttpResult Status416RequestedRangeNotSatisfiable = new StatusCodeHttpResult(StatusCodes.Status416RequestedRangeNotSatisfiable); + private static readonly StatusCodeHttpResult Status417ExpectationFailed = new StatusCodeHttpResult(StatusCodes.Status417ExpectationFailed); + private static readonly StatusCodeHttpResult Status418ImATeapot = new StatusCodeHttpResult(StatusCodes.Status418ImATeapot); + private static readonly StatusCodeHttpResult Status419AuthenticationTimeout = new StatusCodeHttpResult(StatusCodes.Status419AuthenticationTimeout); + private static readonly StatusCodeHttpResult Status421MisdirectedRequest = new StatusCodeHttpResult(StatusCodes.Status421MisdirectedRequest); + private static readonly StatusCodeHttpResult Status422UnprocessableEntity = new StatusCodeHttpResult(StatusCodes.Status422UnprocessableEntity); + private static readonly StatusCodeHttpResult Status423Locked = new StatusCodeHttpResult(StatusCodes.Status423Locked); + private static readonly StatusCodeHttpResult Status424FailedDependency = new StatusCodeHttpResult(StatusCodes.Status424FailedDependency); + private static readonly StatusCodeHttpResult Status426UpgradeRequired = new StatusCodeHttpResult(StatusCodes.Status426UpgradeRequired); + private static readonly StatusCodeHttpResult Status428PreconditionRequired = new StatusCodeHttpResult(StatusCodes.Status428PreconditionRequired); + private static readonly StatusCodeHttpResult Status429TooManyRequests = new StatusCodeHttpResult(StatusCodes.Status429TooManyRequests); + private static readonly StatusCodeHttpResult Status431RequestHeaderFieldsTooLarge = new StatusCodeHttpResult(StatusCodes.Status431RequestHeaderFieldsTooLarge); + private static readonly StatusCodeHttpResult Status451UnavailableForLegalReasons = new StatusCodeHttpResult(StatusCodes.Status451UnavailableForLegalReasons); + private static readonly StatusCodeHttpResult Status500InternalServerError = new StatusCodeHttpResult(StatusCodes.Status500InternalServerError); + private static readonly StatusCodeHttpResult Status501NotImplemented = new StatusCodeHttpResult(StatusCodes.Status501NotImplemented); + private static readonly StatusCodeHttpResult Status502BadGateway = new StatusCodeHttpResult(StatusCodes.Status502BadGateway); + private static readonly StatusCodeHttpResult Status503ServiceUnavailable = new StatusCodeHttpResult(StatusCodes.Status503ServiceUnavailable); + private static readonly StatusCodeHttpResult Status504GatewayTimeout = new StatusCodeHttpResult(StatusCodes.Status504GatewayTimeout); + private static readonly StatusCodeHttpResult Status505HttpVersionNotsupported = new StatusCodeHttpResult(StatusCodes.Status505HttpVersionNotsupported); + private static readonly StatusCodeHttpResult Status506VariantAlsoNegotiates = new StatusCodeHttpResult(StatusCodes.Status506VariantAlsoNegotiates); + private static readonly StatusCodeHttpResult Status507InsufficientStorage = new StatusCodeHttpResult(StatusCodes.Status507InsufficientStorage); + private static readonly StatusCodeHttpResult Status508LoopDetected = new StatusCodeHttpResult(StatusCodes.Status508LoopDetected); + private static readonly StatusCodeHttpResult Status510NotExtended = new StatusCodeHttpResult(StatusCodes.Status510NotExtended); + private static readonly StatusCodeHttpResult Status511NetworkAuthenticationRequired = new StatusCodeHttpResult(StatusCodes.Status511NetworkAuthenticationRequired); + + internal static StatusCodeHttpResult StatusCode(int statusCode) + { + return statusCode switch + { + StatusCodes.Status100Continue => Status100Continue, + StatusCodes.Status101SwitchingProtocols => Status101SwitchingProtocols, + StatusCodes.Status102Processing => Status102Processing, + StatusCodes.Status200OK => Status200OK, + StatusCodes.Status201Created => Status201Created, + StatusCodes.Status202Accepted => Status202Accepted, + StatusCodes.Status203NonAuthoritative => Status203NonAuthoritative, + StatusCodes.Status204NoContent => Status204NoContent, + StatusCodes.Status205ResetContent => Status205ResetContent, + StatusCodes.Status206PartialContent => Status206PartialContent, + StatusCodes.Status207MultiStatus => Status207MultiStatus, + StatusCodes.Status208AlreadyReported => Status208AlreadyReported, + StatusCodes.Status226IMUsed => Status226IMUsed, + StatusCodes.Status300MultipleChoices => Status300MultipleChoices, + StatusCodes.Status301MovedPermanently => Status301MovedPermanently, + StatusCodes.Status302Found => Status302Found, + StatusCodes.Status303SeeOther => Status303SeeOther, + StatusCodes.Status304NotModified => Status304NotModified, + StatusCodes.Status305UseProxy => Status305UseProxy, + StatusCodes.Status306SwitchProxy => Status306SwitchProxy, + StatusCodes.Status307TemporaryRedirect => Status307TemporaryRedirect, + StatusCodes.Status308PermanentRedirect => Status308PermanentRedirect, + StatusCodes.Status400BadRequest => Status400BadRequest, + StatusCodes.Status401Unauthorized => Status401Unauthorized, + StatusCodes.Status402PaymentRequired => Status402PaymentRequired, + StatusCodes.Status403Forbidden => Status403Forbidden, + StatusCodes.Status404NotFound => Status404NotFound, + StatusCodes.Status405MethodNotAllowed => Status405MethodNotAllowed, + StatusCodes.Status406NotAcceptable => Status406NotAcceptable, + StatusCodes.Status407ProxyAuthenticationRequired => Status407ProxyAuthenticationRequired, + StatusCodes.Status408RequestTimeout => Status408RequestTimeout, + StatusCodes.Status409Conflict => Status409Conflict, + StatusCodes.Status410Gone => Status410Gone, + StatusCodes.Status411LengthRequired => Status411LengthRequired, + StatusCodes.Status412PreconditionFailed => Status412PreconditionFailed, + StatusCodes.Status413RequestEntityTooLarge => Status413RequestEntityTooLarge, + StatusCodes.Status414RequestUriTooLong => Status414RequestUriTooLong, + StatusCodes.Status415UnsupportedMediaType => Status415UnsupportedMediaType, + StatusCodes.Status416RequestedRangeNotSatisfiable => Status416RequestedRangeNotSatisfiable, + StatusCodes.Status417ExpectationFailed => Status417ExpectationFailed, + StatusCodes.Status418ImATeapot => Status418ImATeapot, + StatusCodes.Status419AuthenticationTimeout => Status419AuthenticationTimeout, + StatusCodes.Status421MisdirectedRequest => Status421MisdirectedRequest, + StatusCodes.Status422UnprocessableEntity => Status422UnprocessableEntity, + StatusCodes.Status423Locked => Status423Locked, + StatusCodes.Status424FailedDependency => Status424FailedDependency, + StatusCodes.Status426UpgradeRequired => Status426UpgradeRequired, + StatusCodes.Status428PreconditionRequired => Status428PreconditionRequired, + StatusCodes.Status429TooManyRequests => Status429TooManyRequests, + StatusCodes.Status431RequestHeaderFieldsTooLarge => Status431RequestHeaderFieldsTooLarge, + StatusCodes.Status451UnavailableForLegalReasons => Status451UnavailableForLegalReasons, + StatusCodes.Status500InternalServerError => Status500InternalServerError, + StatusCodes.Status501NotImplemented => Status501NotImplemented, + StatusCodes.Status502BadGateway => Status502BadGateway, + StatusCodes.Status503ServiceUnavailable => Status503ServiceUnavailable, + StatusCodes.Status504GatewayTimeout => Status504GatewayTimeout, + StatusCodes.Status505HttpVersionNotsupported => Status505HttpVersionNotsupported, + StatusCodes.Status506VariantAlsoNegotiates => Status506VariantAlsoNegotiates, + StatusCodes.Status507InsufficientStorage => Status507InsufficientStorage, + StatusCodes.Status508LoopDetected => Status508LoopDetected, + StatusCodes.Status510NotExtended => Status510NotExtended, + StatusCodes.Status511NetworkAuthenticationRequired => Status511NetworkAuthenticationRequired, + _ => new StatusCodeHttpResult(statusCode), + }; + } +} diff --git a/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt b/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt new file mode 100644 index 000000000000..2ad1b0759c14 --- /dev/null +++ b/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt @@ -0,0 +1,98 @@ +<#@ template debug="true" hostspecific="true" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ output extension=".cs" #> +<# + /// A collection of constants for + /// HTTP status codes. + var statusCodes = new[] + { + new { StatusCode = 100, Name = "100Continue"}, + new { StatusCode = 101, Name = "101SwitchingProtocols"}, + new { StatusCode = 102, Name = "102Processing"}, + new { StatusCode = 200, Name = "200OK"}, + new { StatusCode = 201, Name = "201Created"}, + new { StatusCode = 202, Name = "202Accepted"}, + new { StatusCode = 203, Name = "203NonAuthoritative"}, + new { StatusCode = 204, Name = "204NoContent"}, + new { StatusCode = 205, Name = "205ResetContent"}, + new { StatusCode = 206, Name = "206PartialContent"}, + new { StatusCode = 207, Name = "207MultiStatus"}, + new { StatusCode = 208, Name = "208AlreadyReported"}, + new { StatusCode = 226, Name = "226IMUsed"}, + new { StatusCode = 300, Name = "300MultipleChoices"}, + new { StatusCode = 301, Name = "301MovedPermanently"}, + new { StatusCode = 302, Name = "302Found"}, + new { StatusCode = 303, Name = "303SeeOther"}, + new { StatusCode = 304, Name = "304NotModified"}, + new { StatusCode = 305, Name = "305UseProxy"}, + new { StatusCode = 306, Name = "306SwitchProxy"}, + new { StatusCode = 307, Name = "307TemporaryRedirect"}, + new { StatusCode = 308, Name = "308PermanentRedirect"}, + new { StatusCode = 400, Name = "400BadRequest"}, + new { StatusCode = 401, Name = "401Unauthorized"}, + new { StatusCode = 402, Name = "402PaymentRequired"}, + new { StatusCode = 403, Name = "403Forbidden"}, + new { StatusCode = 404, Name = "404NotFound"}, + new { StatusCode = 405, Name = "405MethodNotAllowed"}, + new { StatusCode = 406, Name = "406NotAcceptable"}, + new { StatusCode = 407, Name = "407ProxyAuthenticationRequired"}, + new { StatusCode = 408, Name = "408RequestTimeout"}, + new { StatusCode = 409, Name = "409Conflict"}, + new { StatusCode = 410, Name = "410Gone"}, + new { StatusCode = 411, Name = "411LengthRequired"}, + new { StatusCode = 412, Name = "412PreconditionFailed"}, + new { StatusCode = 413, Name = "413RequestEntityTooLarge"}, + new { StatusCode = 414, Name = "414RequestUriTooLong"}, + new { StatusCode = 415, Name = "415UnsupportedMediaType"}, + new { StatusCode = 416, Name = "416RequestedRangeNotSatisfiable"}, + new { StatusCode = 417, Name = "417ExpectationFailed"}, + new { StatusCode = 418, Name = "418ImATeapot"}, + new { StatusCode = 419, Name = "419AuthenticationTimeout"}, + new { StatusCode = 421, Name = "421MisdirectedRequest"}, + new { StatusCode = 422, Name = "422UnprocessableEntity"}, + new { StatusCode = 423, Name = "423Locked"}, + new { StatusCode = 424, Name = "424FailedDependency"}, + new { StatusCode = 426, Name = "426UpgradeRequired"}, + new { StatusCode = 428, Name = "428PreconditionRequired"}, + new { StatusCode = 429, Name = "429TooManyRequests"}, + new { StatusCode = 431, Name = "431RequestHeaderFieldsTooLarge"}, + new { StatusCode = 451, Name = "451UnavailableForLegalReasons"}, + new { StatusCode = 500, Name = "500InternalServerError"}, + new { StatusCode = 501, Name = "501NotImplemented"}, + new { StatusCode = 502, Name = "502BadGateway"}, + new { StatusCode = 503, Name = "503ServiceUnavailable"}, + new { StatusCode = 504, Name = "504GatewayTimeout"}, + new { StatusCode = 505, Name = "505HttpVersionNotsupported"}, + new { StatusCode = 506, Name = "506VariantAlsoNegotiates"}, + new { StatusCode = 507, Name = "507InsufficientStorage"}, + new { StatusCode = 508, Name = "508LoopDetected"}, + new { StatusCode = 510, Name = "510NotExtended"}, + new { StatusCode = 511, Name = "511NetworkAuthenticationRequired"}, + }; +#> +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +namespace Microsoft.AspNetCore.Http; + +using System.CodeDom.Compiler; + +[GeneratedCode("TextTemplatingFileGenerator", "")] +internal static partial class ResultsCache +{ +<# foreach (var statusCode in statusCodes) { #> + private static readonly StatusCodeHttpResult Status<#= statusCode.Name #> = new StatusCodeHttpResult(StatusCodes.Status<#= statusCode.Name #>); +<# } #> + + internal static StatusCodeHttpResult StatusCode(int statusCode) + { + return statusCode switch + { +<# foreach (var statusCode in statusCodes) { #> + StatusCodes.Status<#= statusCode.Name #> => Status<#= statusCode.Name #>, +<# } #> + _ => new StatusCodeHttpResult(statusCode), + }; + } +} diff --git a/src/Http/Http.Results/src/ResultsCache.cs b/src/Http/Http.Results/src/ResultsCache.cs new file mode 100644 index 000000000000..0137f6b699d4 --- /dev/null +++ b/src/Http/Http.Results/src/ResultsCache.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Http; + +internal static partial class ResultsCache +{ + public static NotFoundObjectHttpResult NotFound { get; } = new(); + public static UnauthorizedHttpResult Unauthorized { get; } = new(); + public static BadRequestObjectHttpResult BadRequest { get; } = new(); + public static ConflictObjectHttpResult Conflict { get; } = new(); + public static NoContentHttpResult NoContent { get; } = new(); + public static OkObjectHttpResult Ok { get; } = new(); + public static UnprocessableEntityObjectHttpResult UnprocessableEntity { get; } = new(); +} From 480a11b547c9b705332dd261c111ffdd9a5aa349 Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Tue, 29 Mar 2022 13:05:00 -0700 Subject: [PATCH 4/6] Updated ctors --- .../Http.Results/src/AcceptedHttpResult.cs | 24 +------ .../src/BadRequestObjectHttpResult.cs | 5 -- .../Http.Results/src/ChallengeHttpResult.cs | 10 +-- .../src/ConflictObjectHttpResult.cs | 5 -- .../Http.Results/src/ContentHttpResult.cs | 18 +---- .../Http.Results/src/CreatedHttpResult.cs | 24 +------ src/Http/Http.Results/src/EmptyHttpResult.cs | 9 --- .../Http.Results/src/FileContentHttpResult.cs | 11 +-- .../Http.Results/src/FileStreamHttpResult.cs | 11 +-- src/Http/Http.Results/src/JsonHttpResult.cs | 11 +-- .../Microsoft.AspNetCore.Http.Results.csproj | 29 ++++++++ .../Http.Results/src/NoContentHttpResult.cs | 12 ---- .../src/NotFoundObjectHttpResult.cs | 5 -- .../Http.Results/src/OkObjectHttpResult.cs | 5 -- .../src/PhysicalFileHttpResult.cs | 11 +-- .../Http.Results/src/PublicAPI.Unshipped.txt | 18 ++--- .../Http.Results/src/PushStreamHttpResult.cs | 11 +-- .../Http.Results/src/RedirectHttpResult.cs | 12 +--- .../src/RedirectToRouteHttpResult.cs | 20 +----- .../Http.Results/src/StatusCodeHttpResult.cs | 69 ------------------- .../src/UnauthorizedHttpResult.cs | 12 ---- .../UnprocessableEntityObjectHttpResult.cs | 5 -- .../Http.Results/src/VirtualFileHttpResult.cs | 11 +-- .../Http.Results/test/NoContentResultTests.cs | 4 +- .../test/UnauthorizedResultTests.cs | 4 +- 25 files changed, 54 insertions(+), 302 deletions(-) diff --git a/src/Http/Http.Results/src/AcceptedHttpResult.cs b/src/Http/Http.Results/src/AcceptedHttpResult.cs index 0608215cdabd..7431b034d260 100644 --- a/src/Http/Http.Results/src/AcceptedHttpResult.cs +++ b/src/Http/Http.Results/src/AcceptedHttpResult.cs @@ -14,46 +14,26 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class AcceptedHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The location at which the status of requested content can be monitored. - public AcceptedHttpResult(string? location) - : this(location, null) - { - } - /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - public AcceptedHttpResult(string? location, object? value) + public AcceptedHttpResult(string? location, object? value = null) { Value = value; Location = location; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The location at which the status of requested content can be monitored. - public AcceptedHttpResult(Uri locationUri) - : this(locationUri, null) - { - } - /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - public AcceptedHttpResult(Uri locationUri, object? value) + public AcceptedHttpResult(Uri locationUri, object? value = null) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs index 997fb1c79ead..9c3646af7cc8 100644 --- a/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs +++ b/src/Http/Http.Results/src/BadRequestObjectHttpResult.cs @@ -23,11 +23,6 @@ public BadRequestObjectHttpResult(object? error = null) HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of with a null . - /// - public static BadRequestObjectHttpResult Instance { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/ChallengeHttpResult.cs b/src/Http/Http.Results/src/ChallengeHttpResult.cs index 0588438254e9..074cdf405472 100644 --- a/src/Http/Http.Results/src/ChallengeHttpResult.cs +++ b/src/Http/Http.Results/src/ChallengeHttpResult.cs @@ -13,21 +13,13 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class ChallengeHttpResult : IResult { - /// - /// Initializes a new instance of with the default sign out scheme. - /// - public ChallengeHttpResult() - : this(properties: null, authenticationSchemes: Array.Empty()) - { - } - /// /// Initializes a new instance of with the /// specified . /// /// used to perform the authentication /// challenge. - public ChallengeHttpResult(AuthenticationProperties? properties) + public ChallengeHttpResult(AuthenticationProperties? properties = null) : this(properties, authenticationSchemes: Array.Empty()) { } diff --git a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs index b4ccbb05946d..a09b05d7512f 100644 --- a/src/Http/Http.Results/src/ConflictObjectHttpResult.cs +++ b/src/Http/Http.Results/src/ConflictObjectHttpResult.cs @@ -23,11 +23,6 @@ public ConflictObjectHttpResult(object? error = null) HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of with a null . - /// - public static ConflictObjectHttpResult Instance { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/ContentHttpResult.cs b/src/Http/Http.Results/src/ContentHttpResult.cs index 8ac18dace983..32ef30d67b18 100644 --- a/src/Http/Http.Results/src/ContentHttpResult.cs +++ b/src/Http/Http.Results/src/ContentHttpResult.cs @@ -12,28 +12,12 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class ContentHttpResult : IResult { - /// - /// Initializes a new instance of the class - /// - public ContentHttpResult() - { - } - - /// - /// Initializes a new instance of the class with the values - /// - /// The value to format in the entity body. - public ContentHttpResult(string content) - { - Content = content; - } - /// /// Initializes a new instance of the class with the values /// /// The value to format in the entity body. /// The Content-Type header for the response - public ContentHttpResult(string content, string contentType) + public ContentHttpResult(string? content = null, string? contentType = null) { Content = content; ContentType = contentType; diff --git a/src/Http/Http.Results/src/CreatedHttpResult.cs b/src/Http/Http.Results/src/CreatedHttpResult.cs index 62e12334ad51..1bcae656a740 100644 --- a/src/Http/Http.Results/src/CreatedHttpResult.cs +++ b/src/Http/Http.Results/src/CreatedHttpResult.cs @@ -12,46 +12,26 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class CreatedHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The location at which the status of requested content can be monitored. - public CreatedHttpResult(string? location) - : this(location, null) - { - } - /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - public CreatedHttpResult(string? location, object? value) + public CreatedHttpResult(string? location, object? value = null) { Value = value; Location = location; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The location at which the status of requested content can be monitored. - public CreatedHttpResult(Uri locationUri) - : this(locationUri, null) - { - } - /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. - public CreatedHttpResult(Uri locationUri, object? value) + public CreatedHttpResult(Uri locationUri, object? value = null) { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/EmptyHttpResult.cs b/src/Http/Http.Results/src/EmptyHttpResult.cs index 9e9b25c166dd..8f5e4544fd25 100644 --- a/src/Http/Http.Results/src/EmptyHttpResult.cs +++ b/src/Http/Http.Results/src/EmptyHttpResult.cs @@ -9,15 +9,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class EmptyHttpResult : IResult { - private EmptyHttpResult() - { - } - - /// - /// Gets an instance of . - /// - public static EmptyHttpResult Instance { get; } = new(); - /// public Task ExecuteAsync(HttpContext httpContext) { diff --git a/src/Http/Http.Results/src/FileContentHttpResult.cs b/src/Http/Http.Results/src/FileContentHttpResult.cs index 0af5236a82af..9a333dd98d8e 100644 --- a/src/Http/Http.Results/src/FileContentHttpResult.cs +++ b/src/Http/Http.Results/src/FileContentHttpResult.cs @@ -14,21 +14,12 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class FileContentHttpResult : IResult { - /// - /// Creates a new instance with the provided values. - /// - /// The bytes that represent the file contents. - public FileContentHttpResult(ReadOnlyMemory fileContents) - : this(fileContents, contentType: null) - { - } - /// /// Creates a new instance with the provided values. /// /// The bytes that represent the file contents. /// The Content-Type header of the response. - public FileContentHttpResult(ReadOnlyMemory fileContents, string? contentType) + public FileContentHttpResult(ReadOnlyMemory fileContents, string? contentType = null) { FileContents = fileContents; FileLength = fileContents.Length; diff --git a/src/Http/Http.Results/src/FileStreamHttpResult.cs b/src/Http/Http.Results/src/FileStreamHttpResult.cs index 70d2ab51cef5..848d0fa8518c 100644 --- a/src/Http/Http.Results/src/FileStreamHttpResult.cs +++ b/src/Http/Http.Results/src/FileStreamHttpResult.cs @@ -14,21 +14,12 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class FileStreamHttpResult : IResult { - /// - /// Creates a new instance with the provided values. - /// - /// The stream with the file. - public FileStreamHttpResult(Stream fileStream) - : this(fileStream, contentType: null) - { - } - /// /// Creates a new instance with the provided values. /// /// The stream with the file. /// The Content-Type header of the response. - public FileStreamHttpResult(Stream fileStream, string? contentType) + public FileStreamHttpResult(Stream fileStream, string? contentType = null) { if (fileStream == null) { diff --git a/src/Http/Http.Results/src/JsonHttpResult.cs b/src/Http/Http.Results/src/JsonHttpResult.cs index 10fcac55c003..5cc12be56d53 100644 --- a/src/Http/Http.Results/src/JsonHttpResult.cs +++ b/src/Http/Http.Results/src/JsonHttpResult.cs @@ -14,21 +14,12 @@ public sealed class JsonHttpResult : IResult { private int? _statusCode; - /// - /// Initializes a new instance of the class with the values. - /// - /// The value to format in the entity body. - public JsonHttpResult(object? value) - : this(value, null) - { - } - /// /// Initializes a new instance of the class with the values. /// /// The value to format in the entity body. /// The serializer settings. - public JsonHttpResult(object? value, JsonSerializerOptions? jsonSerializerOptions) + public JsonHttpResult(object? value = null, JsonSerializerOptions? jsonSerializerOptions = null) { Value = value; JsonSerializerOptions = jsonSerializerOptions; diff --git a/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj b/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj index cfa2eb2e0da9..be63787d67a7 100644 --- a/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj +++ b/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj @@ -28,4 +28,33 @@ + + + TextTemplatingFileGenerator + ResultsCache.StatusCodes.cs + + + + + + + + + + True + True + KnownStatusCodeHttpResults.tt + + + True + True + ResultsCache.StatusCodes.tt + + + True + True + StatusCodeHttpResult.Cache.tt + + + diff --git a/src/Http/Http.Results/src/NoContentHttpResult.cs b/src/Http/Http.Results/src/NoContentHttpResult.cs index 804b0bbbf572..078e7db2b948 100644 --- a/src/Http/Http.Results/src/NoContentHttpResult.cs +++ b/src/Http/Http.Results/src/NoContentHttpResult.cs @@ -12,18 +12,6 @@ namespace Microsoft.AspNetCore.Http; /// public class NoContentHttpResult : IResult { - /// - /// Initializes a new instance of the class. - /// - private NoContentHttpResult() - { - } - - /// - /// Gets an instance of . - /// - public static NoContentHttpResult Instance { get; } = new(); - /// /// Gets the HTTP status code. /// diff --git a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs index 4a1e0816e444..02560a93e2ce 100644 --- a/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs +++ b/src/Http/Http.Results/src/NotFoundObjectHttpResult.cs @@ -22,11 +22,6 @@ public NotFoundObjectHttpResult(object? value = null) HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of with a null . - /// - public static NotFoundObjectHttpResult Instance { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/OkObjectHttpResult.cs b/src/Http/Http.Results/src/OkObjectHttpResult.cs index ebd249299cfa..bfb671fd9c4a 100644 --- a/src/Http/Http.Results/src/OkObjectHttpResult.cs +++ b/src/Http/Http.Results/src/OkObjectHttpResult.cs @@ -23,11 +23,6 @@ public OkObjectHttpResult(object? value = null) HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of with a null . - /// - public static OkObjectHttpResult Instance { get; } = new(); - /// /// Gets the object result. /// diff --git a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs index 9229393c6644..b2e857932e33 100644 --- a/src/Http/Http.Results/src/PhysicalFileHttpResult.cs +++ b/src/Http/Http.Results/src/PhysicalFileHttpResult.cs @@ -15,21 +15,12 @@ public sealed partial class PhysicalFileHttpResult : IResult { private DateTimeOffset? _lastModified; - /// - /// Creates a new instance with the provided values. - /// - /// The path to the file. The path must be an absolute path. - public PhysicalFileHttpResult(string fileName) - : this(fileName, contentType: null) - { - } - /// /// Creates a new instance with the provided values. /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - public PhysicalFileHttpResult(string fileName, string? contentType) + public PhysicalFileHttpResult(string fileName, string? contentType = null) { FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); ContentType = contentType ?? "application/octet-stream"; diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index b8cdff7e6178..8ba5c70e4460 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -7,10 +7,8 @@ Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.RouteValues.get -> Microsoft Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.AcceptedAtRouteHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.AcceptedHttpResult -Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(System.Uri! locationUri) -> void -Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(System.Uri! locationUri, object? value) -> void -Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(string? location) -> void -Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(string? location, object? value) -> void +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(System.Uri! locationUri, object? value = null) -> void +Microsoft.AspNetCore.Http.AcceptedHttpResult.AcceptedHttpResult(string? location, object? value = null) -> void Microsoft.AspNetCore.Http.AcceptedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.AcceptedHttpResult.Location.get -> string? Microsoft.AspNetCore.Http.AcceptedHttpResult.StatusCode.get -> int @@ -22,10 +20,8 @@ Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ChallengeHttpResult Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult() -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null, System.Collections.Generic.IList! authenticationSchemes = null) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null, string! authenticationScheme = null) -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ChallengeHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.ConflictObjectHttpResult @@ -59,6 +55,7 @@ Microsoft.AspNetCore.Http.CreatedHttpResult.Location.get -> string? Microsoft.AspNetCore.Http.CreatedHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.CreatedHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.EmptyHttpResult +Microsoft.AspNetCore.Http.EmptyHttpResult.EmptyHttpResult() -> void Microsoft.AspNetCore.Http.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.FileContentHttpResult Microsoft.AspNetCore.Http.FileContentHttpResult.ContentType.get -> string! @@ -110,6 +107,7 @@ Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.NoContentHttpResult Microsoft.AspNetCore.Http.NoContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.NoContentHttpResult.NoContentHttpResult() -> void Microsoft.AspNetCore.Http.NoContentHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.NotFoundObjectHttpResult Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -204,6 +202,7 @@ Microsoft.AspNetCore.Http.StatusCodeHttpResult.StatusCodeHttpResult(int statusCo Microsoft.AspNetCore.Http.UnauthorizedHttpResult Microsoft.AspNetCore.Http.UnauthorizedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.UnauthorizedHttpResult.StatusCode.get -> int +Microsoft.AspNetCore.Http.UnauthorizedHttpResult.UnauthorizedHttpResult() -> void Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.StatusCode.get -> int @@ -226,13 +225,10 @@ Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fi Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName, string? contentType) -> void static Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.BadRequestObjectHttpResult! static Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.ConflictObjectHttpResult! -static Microsoft.AspNetCore.Http.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.EmptyHttpResult! -static Microsoft.AspNetCore.Http.NoContentHttpResult.Instance.get -> Microsoft.AspNetCore.Http.NoContentHttpResult! static Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.NotFoundObjectHttpResult! static Microsoft.AspNetCore.Http.OkObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.OkObjectHttpResult! static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! -static Microsoft.AspNetCore.Http.UnauthorizedHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnauthorizedHttpResult! static Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult! diff --git a/src/Http/Http.Results/src/PushStreamHttpResult.cs b/src/Http/Http.Results/src/PushStreamHttpResult.cs index 9d6168ef47b9..7ded72e60b54 100644 --- a/src/Http/Http.Results/src/PushStreamHttpResult.cs +++ b/src/Http/Http.Results/src/PushStreamHttpResult.cs @@ -15,21 +15,12 @@ public sealed class PushStreamHttpResult : IResult { private readonly Func _streamWriterCallback; - /// - /// Creates a new instance with the provided values. - /// - /// The stream writer callback. - public PushStreamHttpResult(Func streamWriterCallback) - : this(streamWriterCallback, contentType: null) - { - } - /// /// Creates a new instance with the provided values. /// /// The stream writer callback. /// The Content-Type header of the response. - public PushStreamHttpResult(Func streamWriterCallback, string? contentType) + public PushStreamHttpResult(Func streamWriterCallback, string? contentType = null) { _streamWriterCallback = streamWriterCallback; ContentType = contentType ?? "application/octet-stream"; diff --git a/src/Http/Http.Results/src/RedirectHttpResult.cs b/src/Http/Http.Results/src/RedirectHttpResult.cs index 89095a7453b4..4273ea03b113 100644 --- a/src/Http/Http.Results/src/RedirectHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectHttpResult.cs @@ -13,16 +13,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class RedirectHttpResult : IResult { - /// - /// Initializes a new instance of the class with the values - /// provided. - /// - /// The URL to redirect to. - public RedirectHttpResult(string url) - : this(url, acceptLocalUrlOnly: false) - { - } - /// /// Initializes a new instance of the class with the values /// provided. @@ -30,7 +20,7 @@ public RedirectHttpResult(string url) /// The URL to redirect to. /// If set to true, only local URLs are accepted /// and will throw an exception when the supplied URL is not considered local. - public RedirectHttpResult(string url, bool acceptLocalUrlOnly) + public RedirectHttpResult(string url, bool acceptLocalUrlOnly = false) { if (url == null) { diff --git a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs index 45f594c15689..694701c8c4db 100644 --- a/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs +++ b/src/Http/Http.Results/src/RedirectToRouteHttpResult.cs @@ -14,31 +14,13 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class RedirectToRouteHttpResult : IResult { - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The parameters for the route. - public RedirectToRouteHttpResult(object routeValues) - : this(routeName: null, routeValues) - { } - - /// - /// Initializes a new instance of the with the values - /// provided. - /// - /// The name of the route. - public RedirectToRouteHttpResult(string routeName) - : this(routeName, routeValues: null) - { } - /// /// Initializes a new instance of the with the values /// provided. /// /// The name of the route. /// The parameters for the route. - public RedirectToRouteHttpResult(string? routeName, object? routeValues) + public RedirectToRouteHttpResult(string? routeName = null, object? routeValues = null) { RouteName = routeName; RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues); diff --git a/src/Http/Http.Results/src/StatusCodeHttpResult.cs b/src/Http/Http.Results/src/StatusCodeHttpResult.cs index 5c9c049a99e0..a6422912b6ef 100644 --- a/src/Http/Http.Results/src/StatusCodeHttpResult.cs +++ b/src/Http/Http.Results/src/StatusCodeHttpResult.cs @@ -12,75 +12,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class StatusCodeHttpResult : IResult { - internal static readonly IReadOnlyDictionary KnownStatusCodes = new Dictionary - { - [StatusCodes.Status100Continue] = new StatusCodeHttpResult(StatusCodes.Status100Continue), - [StatusCodes.Status101SwitchingProtocols] = new StatusCodeHttpResult(StatusCodes.Status101SwitchingProtocols), - [StatusCodes.Status102Processing] = new StatusCodeHttpResult(StatusCodes.Status102Processing), - [StatusCodes.Status200OK] = new StatusCodeHttpResult(StatusCodes.Status200OK), - [StatusCodes.Status201Created] = new StatusCodeHttpResult(StatusCodes.Status201Created), - [StatusCodes.Status202Accepted] = new StatusCodeHttpResult(StatusCodes.Status202Accepted), - [StatusCodes.Status203NonAuthoritative] = new StatusCodeHttpResult(StatusCodes.Status203NonAuthoritative), - [StatusCodes.Status204NoContent] = new StatusCodeHttpResult(StatusCodes.Status204NoContent), - [StatusCodes.Status205ResetContent] = new StatusCodeHttpResult(StatusCodes.Status205ResetContent), - [StatusCodes.Status206PartialContent] = new StatusCodeHttpResult(StatusCodes.Status206PartialContent), - [StatusCodes.Status207MultiStatus] = new StatusCodeHttpResult(StatusCodes.Status207MultiStatus), - [StatusCodes.Status208AlreadyReported] = new StatusCodeHttpResult(StatusCodes.Status208AlreadyReported), - [StatusCodes.Status226IMUsed] = new StatusCodeHttpResult(StatusCodes.Status226IMUsed), - [StatusCodes.Status300MultipleChoices] = new StatusCodeHttpResult(StatusCodes.Status300MultipleChoices), - [StatusCodes.Status301MovedPermanently] = new StatusCodeHttpResult(StatusCodes.Status301MovedPermanently), - [StatusCodes.Status302Found] = new StatusCodeHttpResult(StatusCodes.Status302Found), - [StatusCodes.Status303SeeOther] = new StatusCodeHttpResult(StatusCodes.Status303SeeOther), - [StatusCodes.Status304NotModified] = new StatusCodeHttpResult(StatusCodes.Status304NotModified), - [StatusCodes.Status305UseProxy] = new StatusCodeHttpResult(StatusCodes.Status305UseProxy), - [StatusCodes.Status306SwitchProxy] = new StatusCodeHttpResult(StatusCodes.Status306SwitchProxy), - [StatusCodes.Status307TemporaryRedirect] = new StatusCodeHttpResult(StatusCodes.Status307TemporaryRedirect), - [StatusCodes.Status308PermanentRedirect] = new StatusCodeHttpResult(StatusCodes.Status308PermanentRedirect), - [StatusCodes.Status400BadRequest] = new StatusCodeHttpResult(StatusCodes.Status400BadRequest), - [StatusCodes.Status401Unauthorized] = new StatusCodeHttpResult(StatusCodes.Status401Unauthorized), - [StatusCodes.Status402PaymentRequired] = new StatusCodeHttpResult(StatusCodes.Status402PaymentRequired), - [StatusCodes.Status403Forbidden] = new StatusCodeHttpResult(StatusCodes.Status403Forbidden), - [StatusCodes.Status404NotFound] = new StatusCodeHttpResult(StatusCodes.Status404NotFound), - [StatusCodes.Status405MethodNotAllowed] = new StatusCodeHttpResult(StatusCodes.Status405MethodNotAllowed), - [StatusCodes.Status406NotAcceptable] = new StatusCodeHttpResult(StatusCodes.Status406NotAcceptable), - [StatusCodes.Status407ProxyAuthenticationRequired] = new StatusCodeHttpResult(StatusCodes.Status407ProxyAuthenticationRequired), - [StatusCodes.Status408RequestTimeout] = new StatusCodeHttpResult(StatusCodes.Status408RequestTimeout), - [StatusCodes.Status409Conflict] = new StatusCodeHttpResult(StatusCodes.Status409Conflict), - [StatusCodes.Status410Gone] = new StatusCodeHttpResult(StatusCodes.Status410Gone), - [StatusCodes.Status411LengthRequired] = new StatusCodeHttpResult(StatusCodes.Status411LengthRequired), - [StatusCodes.Status412PreconditionFailed] = new StatusCodeHttpResult(StatusCodes.Status412PreconditionFailed), - [StatusCodes.Status413RequestEntityTooLarge] = new StatusCodeHttpResult(StatusCodes.Status413RequestEntityTooLarge), - [StatusCodes.Status413PayloadTooLarge] = new StatusCodeHttpResult(StatusCodes.Status413PayloadTooLarge), - [StatusCodes.Status414RequestUriTooLong] = new StatusCodeHttpResult(StatusCodes.Status414RequestUriTooLong), - [StatusCodes.Status414UriTooLong] = new StatusCodeHttpResult(StatusCodes.Status414UriTooLong), - [StatusCodes.Status415UnsupportedMediaType] = new StatusCodeHttpResult(StatusCodes.Status415UnsupportedMediaType), - [StatusCodes.Status416RequestedRangeNotSatisfiable] = new StatusCodeHttpResult(StatusCodes.Status416RequestedRangeNotSatisfiable), - [StatusCodes.Status416RangeNotSatisfiable] = new StatusCodeHttpResult(StatusCodes.Status416RangeNotSatisfiable), - [StatusCodes.Status417ExpectationFailed] = new StatusCodeHttpResult(StatusCodes.Status417ExpectationFailed), - [StatusCodes.Status418ImATeapot] = new StatusCodeHttpResult(StatusCodes.Status418ImATeapot), - [StatusCodes.Status419AuthenticationTimeout] = new StatusCodeHttpResult(StatusCodes.Status419AuthenticationTimeout), - [StatusCodes.Status421MisdirectedRequest] = new StatusCodeHttpResult(StatusCodes.Status421MisdirectedRequest), - [StatusCodes.Status422UnprocessableEntity] = new StatusCodeHttpResult(StatusCodes.Status422UnprocessableEntity), - [StatusCodes.Status423Locked] = new StatusCodeHttpResult(StatusCodes.Status423Locked), - [StatusCodes.Status424FailedDependency] = new StatusCodeHttpResult(StatusCodes.Status424FailedDependency), - [StatusCodes.Status426UpgradeRequired] = new StatusCodeHttpResult(StatusCodes.Status426UpgradeRequired), - [StatusCodes.Status428PreconditionRequired] = new StatusCodeHttpResult(StatusCodes.Status428PreconditionRequired), - [StatusCodes.Status429TooManyRequests] = new StatusCodeHttpResult(StatusCodes.Status429TooManyRequests), - [StatusCodes.Status431RequestHeaderFieldsTooLarge] = new StatusCodeHttpResult(StatusCodes.Status431RequestHeaderFieldsTooLarge), - [StatusCodes.Status451UnavailableForLegalReasons] = new StatusCodeHttpResult(StatusCodes.Status451UnavailableForLegalReasons), - [StatusCodes.Status500InternalServerError] = new StatusCodeHttpResult(StatusCodes.Status500InternalServerError), - [StatusCodes.Status501NotImplemented] = new StatusCodeHttpResult(StatusCodes.Status501NotImplemented), - [StatusCodes.Status502BadGateway] = new StatusCodeHttpResult(StatusCodes.Status502BadGateway), - [StatusCodes.Status503ServiceUnavailable] = new StatusCodeHttpResult(StatusCodes.Status503ServiceUnavailable), - [StatusCodes.Status504GatewayTimeout] = new StatusCodeHttpResult(StatusCodes.Status504GatewayTimeout), - [StatusCodes.Status505HttpVersionNotsupported] = new StatusCodeHttpResult(StatusCodes.Status505HttpVersionNotsupported), - [StatusCodes.Status506VariantAlsoNegotiates] = new StatusCodeHttpResult(StatusCodes.Status506VariantAlsoNegotiates), - [StatusCodes.Status507InsufficientStorage] = new StatusCodeHttpResult(StatusCodes.Status507InsufficientStorage), - [StatusCodes.Status508LoopDetected] = new StatusCodeHttpResult(StatusCodes.Status508LoopDetected), - [StatusCodes.Status510NotExtended] = new StatusCodeHttpResult(StatusCodes.Status510NotExtended), - [StatusCodes.Status511NetworkAuthenticationRequired] = new StatusCodeHttpResult(StatusCodes.Status511NetworkAuthenticationRequired), - }; - /// /// Initializes a new instance of the class /// with the given . diff --git a/src/Http/Http.Results/src/UnauthorizedHttpResult.cs b/src/Http/Http.Results/src/UnauthorizedHttpResult.cs index 4dcfa62e11fe..3bc22122393a 100644 --- a/src/Http/Http.Results/src/UnauthorizedHttpResult.cs +++ b/src/Http/Http.Results/src/UnauthorizedHttpResult.cs @@ -12,18 +12,6 @@ namespace Microsoft.AspNetCore.Http; /// public sealed class UnauthorizedHttpResult : IResult { - /// - /// Initializes a new instance of the class. - /// - private UnauthorizedHttpResult() - { - } - - /// - /// Gets an instance of . - /// - public static UnauthorizedHttpResult Instance { get; } = new(); - /// /// Gets the HTTP status code. /// diff --git a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs index 5bfae9fa96ab..774f439cd244 100644 --- a/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs +++ b/src/Http/Http.Results/src/UnprocessableEntityObjectHttpResult.cs @@ -23,11 +23,6 @@ public UnprocessableEntityObjectHttpResult(object? error = null) HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); } - /// - /// Gets an instance of with a null . - /// - public static UnprocessableEntityObjectHttpResult Instance { get; } = new(); - /// public object? Value { get; internal init; } diff --git a/src/Http/Http.Results/src/VirtualFileHttpResult.cs b/src/Http/Http.Results/src/VirtualFileHttpResult.cs index 453964ab8ed3..5b23d225dcab 100644 --- a/src/Http/Http.Results/src/VirtualFileHttpResult.cs +++ b/src/Http/Http.Results/src/VirtualFileHttpResult.cs @@ -17,21 +17,12 @@ public sealed class VirtualFileHttpResult : IResult { private DateTimeOffset? _lastModified; - /// - /// Creates a new instance with the provided values. - /// - /// The path to the file. The path must be an absolute path. - public VirtualFileHttpResult(string fileName) - : this(fileName, contentType: null) - { - } - /// /// Creates a new instance with the provided values. /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - public VirtualFileHttpResult(string fileName, string? contentType) + public VirtualFileHttpResult(string fileName, string? contentType = null) { FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); ContentType = contentType ?? "application/octet-stream"; diff --git a/src/Http/Http.Results/test/NoContentResultTests.cs b/src/Http/Http.Results/test/NoContentResultTests.cs index 7f997475b979..18b56774b6f5 100644 --- a/src/Http/Http.Results/test/NoContentResultTests.cs +++ b/src/Http/Http.Results/test/NoContentResultTests.cs @@ -13,7 +13,7 @@ public class NoContentResultTests public void NoContentResultTests_InitializesStatusCode() { // Arrange & act - var result = NoContentHttpResult.Instance; + var result = new NoContentHttpResult(); // Assert Assert.Equal(StatusCodes.Status204NoContent, result.StatusCode); @@ -23,7 +23,7 @@ public void NoContentResultTests_InitializesStatusCode() public void NoContentResultTests_ExecuteResultSetsResponseStatusCode() { // Arrange - var result = NoContentHttpResult.Instance; + var result = new NoContentHttpResult(); var httpContext = GetHttpContext(); diff --git a/src/Http/Http.Results/test/UnauthorizedResultTests.cs b/src/Http/Http.Results/test/UnauthorizedResultTests.cs index ce33db419a53..50aab7fd7bf9 100644 --- a/src/Http/Http.Results/test/UnauthorizedResultTests.cs +++ b/src/Http/Http.Results/test/UnauthorizedResultTests.cs @@ -13,7 +13,7 @@ public class UnauthorizedResultTests public void UnauthorizedResult_InitializesStatusCode() { // Arrange & act - var result = UnauthorizedHttpResult.Instance; + var result = new UnauthorizedHttpResult(); // Assert Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode); @@ -23,7 +23,7 @@ public void UnauthorizedResult_InitializesStatusCode() public void UnauthorizedResult_ExecuteResultSetsResponseStatusCode() { // Arrange - var result = UnauthorizedHttpResult.Instance; + var result = new UnauthorizedHttpResult(); var httpContext = GetHttpContext(); From c10de30641d5ca799c02fd0301632c4dae2a13c4 Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Mon, 4 Apr 2022 13:25:13 -0700 Subject: [PATCH 5/6] clean up --- .../Http.Results/src/AcceptedHttpResult.cs | 4 + .../Http.Results/src/ChallengeHttpResult.cs | 2 + .../Http.Results/src/CreatedHttpResult.cs | 4 + .../Microsoft.AspNetCore.Http.Results.csproj | 12 -- .../Http.Results/src/PublicAPI.Unshipped.txt | 45 ++---- src/Http/Http.Results/src/Results.cs | 16 +- .../src/ResultsCache.StatusCodes.cs | 144 ------------------ .../src/ResultsCache.StatusCodes.tt | 98 ------------ src/Http/Http.Results/src/ResultsCache.cs | 15 -- src/Http/Http.Results/test/EmptyResultTest.cs | 2 +- 10 files changed, 33 insertions(+), 309 deletions(-) delete mode 100644 src/Http/Http.Results/src/ResultsCache.StatusCodes.cs delete mode 100644 src/Http/Http.Results/src/ResultsCache.StatusCodes.tt delete mode 100644 src/Http/Http.Results/src/ResultsCache.cs diff --git a/src/Http/Http.Results/src/AcceptedHttpResult.cs b/src/Http/Http.Results/src/AcceptedHttpResult.cs index 7431b034d260..9173f3c28c57 100644 --- a/src/Http/Http.Results/src/AcceptedHttpResult.cs +++ b/src/Http/Http.Results/src/AcceptedHttpResult.cs @@ -20,7 +20,9 @@ public sealed class AcceptedHttpResult : IResult /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public AcceptedHttpResult(string? location, object? value = null) +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { Value = value; Location = location; @@ -33,7 +35,9 @@ public AcceptedHttpResult(string? location, object? value = null) /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public AcceptedHttpResult(Uri locationUri, object? value = null) +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/ChallengeHttpResult.cs b/src/Http/Http.Results/src/ChallengeHttpResult.cs index 074cdf405472..b901e62e40ed 100644 --- a/src/Http/Http.Results/src/ChallengeHttpResult.cs +++ b/src/Http/Http.Results/src/ChallengeHttpResult.cs @@ -19,7 +19,9 @@ public sealed partial class ChallengeHttpResult : IResult /// /// used to perform the authentication /// challenge. +#pragma warning disable RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. public ChallengeHttpResult(AuthenticationProperties? properties = null) +#pragma warning restore RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. : this(properties, authenticationSchemes: Array.Empty()) { } diff --git a/src/Http/Http.Results/src/CreatedHttpResult.cs b/src/Http/Http.Results/src/CreatedHttpResult.cs index 1bcae656a740..d3c719e1f699 100644 --- a/src/Http/Http.Results/src/CreatedHttpResult.cs +++ b/src/Http/Http.Results/src/CreatedHttpResult.cs @@ -18,7 +18,9 @@ public sealed class CreatedHttpResult : IResult /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public CreatedHttpResult(string? location, object? value = null) +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { Value = value; Location = location; @@ -31,7 +33,9 @@ public CreatedHttpResult(string? location, object? value = null) /// /// The location at which the status of requested content can be monitored. /// The value to format in the entity body. +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public CreatedHttpResult(Uri locationUri, object? value = null) +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { Value = value; HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode); diff --git a/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj b/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj index be63787d67a7..3e8f0911c68e 100644 --- a/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj +++ b/src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj @@ -28,13 +28,6 @@ - - - TextTemplatingFileGenerator - ResultsCache.StatusCodes.cs - - - @@ -45,11 +38,6 @@ True KnownStatusCodeHttpResults.tt - - True - True - ResultsCache.StatusCodes.tt - True True diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index 8ba5c70e4460..a67283f9c93c 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -20,8 +20,9 @@ Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ChallengeHttpResult Microsoft.AspNetCore.Http.ChallengeHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null, System.Collections.Generic.IList! authenticationSchemes = null) -> void -Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null, string! authenticationScheme = null) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void +Microsoft.AspNetCore.Http.ChallengeHttpResult.ChallengeHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.ChallengeHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ChallengeHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? Microsoft.AspNetCore.Http.ConflictObjectHttpResult @@ -31,9 +32,7 @@ Microsoft.AspNetCore.Http.ConflictObjectHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.ContentHttpResult Microsoft.AspNetCore.Http.ContentHttpResult.Content.get -> string? -Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult() -> void -Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content) -> void -Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string! content, string! contentType) -> void +Microsoft.AspNetCore.Http.ContentHttpResult.ContentHttpResult(string? content = null, string? contentType = null) -> void Microsoft.AspNetCore.Http.ContentHttpResult.ContentType.get -> string? Microsoft.AspNetCore.Http.ContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.ContentHttpResult.StatusCode.get -> int? @@ -46,10 +45,8 @@ Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.RouteValues.get -> Microsoft. Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.StatusCode.get -> int Microsoft.AspNetCore.Http.CreatedAtRouteHttpResult.Value.get -> object? Microsoft.AspNetCore.Http.CreatedHttpResult -Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(System.Uri! locationUri) -> void -Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(System.Uri! locationUri, object? value) -> void -Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(string? location) -> void -Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(string? location, object? value) -> void +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(System.Uri! locationUri, object? value = null) -> void +Microsoft.AspNetCore.Http.CreatedHttpResult.CreatedHttpResult(string? location, object? value = null) -> void Microsoft.AspNetCore.Http.CreatedHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.CreatedHttpResult.Location.get -> string? Microsoft.AspNetCore.Http.CreatedHttpResult.StatusCode.get -> int @@ -64,8 +61,7 @@ Microsoft.AspNetCore.Http.FileContentHttpResult.EnableRangeProcessing.init -> vo Microsoft.AspNetCore.Http.FileContentHttpResult.EntityTag.get -> Microsoft.Net.Http.Headers.EntityTagHeaderValue? Microsoft.AspNetCore.Http.FileContentHttpResult.EntityTag.init -> void Microsoft.AspNetCore.Http.FileContentHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.FileContentHttpResult.FileContentHttpResult(System.ReadOnlyMemory fileContents) -> void -Microsoft.AspNetCore.Http.FileContentHttpResult.FileContentHttpResult(System.ReadOnlyMemory fileContents, string? contentType) -> void +Microsoft.AspNetCore.Http.FileContentHttpResult.FileContentHttpResult(System.ReadOnlyMemory fileContents, string? contentType = null) -> void Microsoft.AspNetCore.Http.FileContentHttpResult.FileContents.get -> System.ReadOnlyMemory Microsoft.AspNetCore.Http.FileContentHttpResult.FileDownloadName.get -> string? Microsoft.AspNetCore.Http.FileContentHttpResult.FileDownloadName.init -> void @@ -83,8 +79,7 @@ Microsoft.AspNetCore.Http.FileStreamHttpResult.FileDownloadName.get -> string? Microsoft.AspNetCore.Http.FileStreamHttpResult.FileDownloadName.init -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStream.get -> System.IO.Stream! -Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStreamHttpResult(System.IO.Stream! fileStream) -> void -Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStreamHttpResult(System.IO.Stream! fileStream, string? contentType) -> void +Microsoft.AspNetCore.Http.FileStreamHttpResult.FileStreamHttpResult(System.IO.Stream! fileStream, string? contentType = null) -> void Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.get -> System.DateTimeOffset? Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult @@ -99,8 +94,7 @@ Microsoft.AspNetCore.Http.JsonHttpResult Microsoft.AspNetCore.Http.JsonHttpResult.ContentType.get -> string? Microsoft.AspNetCore.Http.JsonHttpResult.ContentType.init -> void Microsoft.AspNetCore.Http.JsonHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value) -> void -Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions) -> void +Microsoft.AspNetCore.Http.JsonHttpResult.JsonHttpResult(object? value = null, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null) -> void Microsoft.AspNetCore.Http.JsonHttpResult.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions? Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.get -> int? Microsoft.AspNetCore.Http.JsonHttpResult.StatusCode.init -> void @@ -132,8 +126,7 @@ Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.PhysicalFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.PhysicalFileHttpResult.LastModified.get -> System.DateTimeOffset? Microsoft.AspNetCore.Http.PhysicalFileHttpResult.LastModified.init -> void -Microsoft.AspNetCore.Http.PhysicalFileHttpResult.PhysicalFileHttpResult(string! fileName) -> void -Microsoft.AspNetCore.Http.PhysicalFileHttpResult.PhysicalFileHttpResult(string! fileName, string? contentType) -> void +Microsoft.AspNetCore.Http.PhysicalFileHttpResult.PhysicalFileHttpResult(string! fileName, string? contentType = null) -> void Microsoft.AspNetCore.Http.ProblemHttpResult Microsoft.AspNetCore.Http.ProblemHttpResult.ContentType.get -> string! Microsoft.AspNetCore.Http.ProblemHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -154,8 +147,7 @@ Microsoft.AspNetCore.Http.PushStreamHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.PushStreamHttpResult.FileLength.init -> void Microsoft.AspNetCore.Http.PushStreamHttpResult.LastModified.get -> System.DateTimeOffset? Microsoft.AspNetCore.Http.PushStreamHttpResult.LastModified.init -> void -Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback) -> void -Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback, string? contentType) -> void +Microsoft.AspNetCore.Http.PushStreamHttpResult.PushStreamHttpResult(System.Func! streamWriterCallback, string? contentType = null) -> void Microsoft.AspNetCore.Http.RedirectHttpResult Microsoft.AspNetCore.Http.RedirectHttpResult.AcceptLocalUrlOnly.get -> bool Microsoft.AspNetCore.Http.RedirectHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -163,8 +155,7 @@ Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectHttpResult.Permanent.init -> void Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectHttpResult.PreserveMethod.init -> void -Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url) -> void -Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url, bool acceptLocalUrlOnly) -> void +Microsoft.AspNetCore.Http.RedirectHttpResult.RedirectHttpResult(string! url, bool acceptLocalUrlOnly = false) -> void Microsoft.AspNetCore.Http.RedirectHttpResult.Url.get -> string! Microsoft.AspNetCore.Http.RedirectToRouteHttpResult Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -174,9 +165,7 @@ Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.init -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.init -> void -Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(object! routeValues) -> void -Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string! routeName) -> void -Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string? routeName, object? routeValues) -> void +Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RedirectToRouteHttpResult(string? routeName = null, object? routeValues = null) -> void Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? Microsoft.AspNetCore.Http.SignInHttpResult @@ -221,14 +210,8 @@ Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.get -> System.DateTimeOffset? Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.init -> void -Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName) -> void -Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName, string? contentType) -> void -static Microsoft.AspNetCore.Http.BadRequestObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.BadRequestObjectHttpResult! -static Microsoft.AspNetCore.Http.ConflictObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.ConflictObjectHttpResult! -static Microsoft.AspNetCore.Http.NotFoundObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.NotFoundObjectHttpResult! -static Microsoft.AspNetCore.Http.OkObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.OkObjectHttpResult! +Microsoft.AspNetCore.Http.VirtualFileHttpResult.VirtualFileHttpResult(string! fileName, string? contentType = null) -> void static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! -static Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult.Instance.get -> Microsoft.AspNetCore.Http.UnprocessableEntityObjectHttpResult! diff --git a/src/Http/Http.Results/src/Results.cs b/src/Http/Http.Results/src/Results.cs index 98d3c265bbda..cc1053f7824c 100644 --- a/src/Http/Http.Results/src/Results.cs +++ b/src/Http/Http.Results/src/Results.cs @@ -527,7 +527,7 @@ public static IResult RedirectToRoute(string? routeName = null, object? routeVal /// The status code to set on the response. /// The created object for the response. public static IResult StatusCode(int statusCode) - => ResultsCache.StatusCode(statusCode); + => new StatusCodeHttpResult(statusCode); /// /// Produces a response. @@ -535,14 +535,14 @@ public static IResult StatusCode(int statusCode) /// The value to be included in the HTTP response body. /// The created for the response. public static IResult NotFound(object? value = null) - => value is null ? ResultsCache.NotFound : new NotFoundObjectHttpResult(value); + => new NotFoundObjectHttpResult(value); /// /// Produces a response. /// /// The created for the response. public static IResult Unauthorized() - => ResultsCache.Unauthorized; + => new UnauthorizedHttpResult(); /// /// Produces a response. @@ -550,7 +550,7 @@ public static IResult Unauthorized() /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult BadRequest(object? error = null) - => error is null ? ResultsCache.BadRequest : new BadRequestObjectHttpResult(error); + => new BadRequestObjectHttpResult(error); /// /// Produces a response. @@ -558,14 +558,14 @@ public static IResult BadRequest(object? error = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult Conflict(object? error = null) - => error is null ? ResultsCache.Conflict : new ConflictObjectHttpResult(error); + => new ConflictObjectHttpResult(error); /// /// Produces a response. /// /// The created for the response. public static IResult NoContent() - => ResultsCache.NoContent; + => new NoContentHttpResult(); /// /// Produces a response. @@ -573,7 +573,7 @@ public static IResult NoContent() /// The value to be included in the HTTP response body. /// The created for the response. public static IResult Ok(object? value = null) - => value is null ? ResultsCache.Ok : new OkObjectHttpResult(value); + => new OkObjectHttpResult(value); /// /// Produces a response. @@ -581,7 +581,7 @@ public static IResult Ok(object? value = null) /// An error object to be included in the HTTP response body. /// The created for the response. public static IResult UnprocessableEntity(object? error = null) - => error is null ? ResultsCache.UnprocessableEntity : new UnprocessableEntityObjectHttpResult(error); + => new UnprocessableEntityObjectHttpResult(error); /// /// Produces a response. diff --git a/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs b/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs deleted file mode 100644 index 02045accc4b0..000000000000 --- a/src/Http/Http.Results/src/ResultsCache.StatusCodes.cs +++ /dev/null @@ -1,144 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -namespace Microsoft.AspNetCore.Http; - -using System.CodeDom.Compiler; - -[GeneratedCode("TextTemplatingFileGenerator", "")] -internal static partial class ResultsCache -{ - private static readonly StatusCodeHttpResult Status100Continue = new StatusCodeHttpResult(StatusCodes.Status100Continue); - private static readonly StatusCodeHttpResult Status101SwitchingProtocols = new StatusCodeHttpResult(StatusCodes.Status101SwitchingProtocols); - private static readonly StatusCodeHttpResult Status102Processing = new StatusCodeHttpResult(StatusCodes.Status102Processing); - private static readonly StatusCodeHttpResult Status200OK = new StatusCodeHttpResult(StatusCodes.Status200OK); - private static readonly StatusCodeHttpResult Status201Created = new StatusCodeHttpResult(StatusCodes.Status201Created); - private static readonly StatusCodeHttpResult Status202Accepted = new StatusCodeHttpResult(StatusCodes.Status202Accepted); - private static readonly StatusCodeHttpResult Status203NonAuthoritative = new StatusCodeHttpResult(StatusCodes.Status203NonAuthoritative); - private static readonly StatusCodeHttpResult Status204NoContent = new StatusCodeHttpResult(StatusCodes.Status204NoContent); - private static readonly StatusCodeHttpResult Status205ResetContent = new StatusCodeHttpResult(StatusCodes.Status205ResetContent); - private static readonly StatusCodeHttpResult Status206PartialContent = new StatusCodeHttpResult(StatusCodes.Status206PartialContent); - private static readonly StatusCodeHttpResult Status207MultiStatus = new StatusCodeHttpResult(StatusCodes.Status207MultiStatus); - private static readonly StatusCodeHttpResult Status208AlreadyReported = new StatusCodeHttpResult(StatusCodes.Status208AlreadyReported); - private static readonly StatusCodeHttpResult Status226IMUsed = new StatusCodeHttpResult(StatusCodes.Status226IMUsed); - private static readonly StatusCodeHttpResult Status300MultipleChoices = new StatusCodeHttpResult(StatusCodes.Status300MultipleChoices); - private static readonly StatusCodeHttpResult Status301MovedPermanently = new StatusCodeHttpResult(StatusCodes.Status301MovedPermanently); - private static readonly StatusCodeHttpResult Status302Found = new StatusCodeHttpResult(StatusCodes.Status302Found); - private static readonly StatusCodeHttpResult Status303SeeOther = new StatusCodeHttpResult(StatusCodes.Status303SeeOther); - private static readonly StatusCodeHttpResult Status304NotModified = new StatusCodeHttpResult(StatusCodes.Status304NotModified); - private static readonly StatusCodeHttpResult Status305UseProxy = new StatusCodeHttpResult(StatusCodes.Status305UseProxy); - private static readonly StatusCodeHttpResult Status306SwitchProxy = new StatusCodeHttpResult(StatusCodes.Status306SwitchProxy); - private static readonly StatusCodeHttpResult Status307TemporaryRedirect = new StatusCodeHttpResult(StatusCodes.Status307TemporaryRedirect); - private static readonly StatusCodeHttpResult Status308PermanentRedirect = new StatusCodeHttpResult(StatusCodes.Status308PermanentRedirect); - private static readonly StatusCodeHttpResult Status400BadRequest = new StatusCodeHttpResult(StatusCodes.Status400BadRequest); - private static readonly StatusCodeHttpResult Status401Unauthorized = new StatusCodeHttpResult(StatusCodes.Status401Unauthorized); - private static readonly StatusCodeHttpResult Status402PaymentRequired = new StatusCodeHttpResult(StatusCodes.Status402PaymentRequired); - private static readonly StatusCodeHttpResult Status403Forbidden = new StatusCodeHttpResult(StatusCodes.Status403Forbidden); - private static readonly StatusCodeHttpResult Status404NotFound = new StatusCodeHttpResult(StatusCodes.Status404NotFound); - private static readonly StatusCodeHttpResult Status405MethodNotAllowed = new StatusCodeHttpResult(StatusCodes.Status405MethodNotAllowed); - private static readonly StatusCodeHttpResult Status406NotAcceptable = new StatusCodeHttpResult(StatusCodes.Status406NotAcceptable); - private static readonly StatusCodeHttpResult Status407ProxyAuthenticationRequired = new StatusCodeHttpResult(StatusCodes.Status407ProxyAuthenticationRequired); - private static readonly StatusCodeHttpResult Status408RequestTimeout = new StatusCodeHttpResult(StatusCodes.Status408RequestTimeout); - private static readonly StatusCodeHttpResult Status409Conflict = new StatusCodeHttpResult(StatusCodes.Status409Conflict); - private static readonly StatusCodeHttpResult Status410Gone = new StatusCodeHttpResult(StatusCodes.Status410Gone); - private static readonly StatusCodeHttpResult Status411LengthRequired = new StatusCodeHttpResult(StatusCodes.Status411LengthRequired); - private static readonly StatusCodeHttpResult Status412PreconditionFailed = new StatusCodeHttpResult(StatusCodes.Status412PreconditionFailed); - private static readonly StatusCodeHttpResult Status413RequestEntityTooLarge = new StatusCodeHttpResult(StatusCodes.Status413RequestEntityTooLarge); - private static readonly StatusCodeHttpResult Status414RequestUriTooLong = new StatusCodeHttpResult(StatusCodes.Status414RequestUriTooLong); - private static readonly StatusCodeHttpResult Status415UnsupportedMediaType = new StatusCodeHttpResult(StatusCodes.Status415UnsupportedMediaType); - private static readonly StatusCodeHttpResult Status416RequestedRangeNotSatisfiable = new StatusCodeHttpResult(StatusCodes.Status416RequestedRangeNotSatisfiable); - private static readonly StatusCodeHttpResult Status417ExpectationFailed = new StatusCodeHttpResult(StatusCodes.Status417ExpectationFailed); - private static readonly StatusCodeHttpResult Status418ImATeapot = new StatusCodeHttpResult(StatusCodes.Status418ImATeapot); - private static readonly StatusCodeHttpResult Status419AuthenticationTimeout = new StatusCodeHttpResult(StatusCodes.Status419AuthenticationTimeout); - private static readonly StatusCodeHttpResult Status421MisdirectedRequest = new StatusCodeHttpResult(StatusCodes.Status421MisdirectedRequest); - private static readonly StatusCodeHttpResult Status422UnprocessableEntity = new StatusCodeHttpResult(StatusCodes.Status422UnprocessableEntity); - private static readonly StatusCodeHttpResult Status423Locked = new StatusCodeHttpResult(StatusCodes.Status423Locked); - private static readonly StatusCodeHttpResult Status424FailedDependency = new StatusCodeHttpResult(StatusCodes.Status424FailedDependency); - private static readonly StatusCodeHttpResult Status426UpgradeRequired = new StatusCodeHttpResult(StatusCodes.Status426UpgradeRequired); - private static readonly StatusCodeHttpResult Status428PreconditionRequired = new StatusCodeHttpResult(StatusCodes.Status428PreconditionRequired); - private static readonly StatusCodeHttpResult Status429TooManyRequests = new StatusCodeHttpResult(StatusCodes.Status429TooManyRequests); - private static readonly StatusCodeHttpResult Status431RequestHeaderFieldsTooLarge = new StatusCodeHttpResult(StatusCodes.Status431RequestHeaderFieldsTooLarge); - private static readonly StatusCodeHttpResult Status451UnavailableForLegalReasons = new StatusCodeHttpResult(StatusCodes.Status451UnavailableForLegalReasons); - private static readonly StatusCodeHttpResult Status500InternalServerError = new StatusCodeHttpResult(StatusCodes.Status500InternalServerError); - private static readonly StatusCodeHttpResult Status501NotImplemented = new StatusCodeHttpResult(StatusCodes.Status501NotImplemented); - private static readonly StatusCodeHttpResult Status502BadGateway = new StatusCodeHttpResult(StatusCodes.Status502BadGateway); - private static readonly StatusCodeHttpResult Status503ServiceUnavailable = new StatusCodeHttpResult(StatusCodes.Status503ServiceUnavailable); - private static readonly StatusCodeHttpResult Status504GatewayTimeout = new StatusCodeHttpResult(StatusCodes.Status504GatewayTimeout); - private static readonly StatusCodeHttpResult Status505HttpVersionNotsupported = new StatusCodeHttpResult(StatusCodes.Status505HttpVersionNotsupported); - private static readonly StatusCodeHttpResult Status506VariantAlsoNegotiates = new StatusCodeHttpResult(StatusCodes.Status506VariantAlsoNegotiates); - private static readonly StatusCodeHttpResult Status507InsufficientStorage = new StatusCodeHttpResult(StatusCodes.Status507InsufficientStorage); - private static readonly StatusCodeHttpResult Status508LoopDetected = new StatusCodeHttpResult(StatusCodes.Status508LoopDetected); - private static readonly StatusCodeHttpResult Status510NotExtended = new StatusCodeHttpResult(StatusCodes.Status510NotExtended); - private static readonly StatusCodeHttpResult Status511NetworkAuthenticationRequired = new StatusCodeHttpResult(StatusCodes.Status511NetworkAuthenticationRequired); - - internal static StatusCodeHttpResult StatusCode(int statusCode) - { - return statusCode switch - { - StatusCodes.Status100Continue => Status100Continue, - StatusCodes.Status101SwitchingProtocols => Status101SwitchingProtocols, - StatusCodes.Status102Processing => Status102Processing, - StatusCodes.Status200OK => Status200OK, - StatusCodes.Status201Created => Status201Created, - StatusCodes.Status202Accepted => Status202Accepted, - StatusCodes.Status203NonAuthoritative => Status203NonAuthoritative, - StatusCodes.Status204NoContent => Status204NoContent, - StatusCodes.Status205ResetContent => Status205ResetContent, - StatusCodes.Status206PartialContent => Status206PartialContent, - StatusCodes.Status207MultiStatus => Status207MultiStatus, - StatusCodes.Status208AlreadyReported => Status208AlreadyReported, - StatusCodes.Status226IMUsed => Status226IMUsed, - StatusCodes.Status300MultipleChoices => Status300MultipleChoices, - StatusCodes.Status301MovedPermanently => Status301MovedPermanently, - StatusCodes.Status302Found => Status302Found, - StatusCodes.Status303SeeOther => Status303SeeOther, - StatusCodes.Status304NotModified => Status304NotModified, - StatusCodes.Status305UseProxy => Status305UseProxy, - StatusCodes.Status306SwitchProxy => Status306SwitchProxy, - StatusCodes.Status307TemporaryRedirect => Status307TemporaryRedirect, - StatusCodes.Status308PermanentRedirect => Status308PermanentRedirect, - StatusCodes.Status400BadRequest => Status400BadRequest, - StatusCodes.Status401Unauthorized => Status401Unauthorized, - StatusCodes.Status402PaymentRequired => Status402PaymentRequired, - StatusCodes.Status403Forbidden => Status403Forbidden, - StatusCodes.Status404NotFound => Status404NotFound, - StatusCodes.Status405MethodNotAllowed => Status405MethodNotAllowed, - StatusCodes.Status406NotAcceptable => Status406NotAcceptable, - StatusCodes.Status407ProxyAuthenticationRequired => Status407ProxyAuthenticationRequired, - StatusCodes.Status408RequestTimeout => Status408RequestTimeout, - StatusCodes.Status409Conflict => Status409Conflict, - StatusCodes.Status410Gone => Status410Gone, - StatusCodes.Status411LengthRequired => Status411LengthRequired, - StatusCodes.Status412PreconditionFailed => Status412PreconditionFailed, - StatusCodes.Status413RequestEntityTooLarge => Status413RequestEntityTooLarge, - StatusCodes.Status414RequestUriTooLong => Status414RequestUriTooLong, - StatusCodes.Status415UnsupportedMediaType => Status415UnsupportedMediaType, - StatusCodes.Status416RequestedRangeNotSatisfiable => Status416RequestedRangeNotSatisfiable, - StatusCodes.Status417ExpectationFailed => Status417ExpectationFailed, - StatusCodes.Status418ImATeapot => Status418ImATeapot, - StatusCodes.Status419AuthenticationTimeout => Status419AuthenticationTimeout, - StatusCodes.Status421MisdirectedRequest => Status421MisdirectedRequest, - StatusCodes.Status422UnprocessableEntity => Status422UnprocessableEntity, - StatusCodes.Status423Locked => Status423Locked, - StatusCodes.Status424FailedDependency => Status424FailedDependency, - StatusCodes.Status426UpgradeRequired => Status426UpgradeRequired, - StatusCodes.Status428PreconditionRequired => Status428PreconditionRequired, - StatusCodes.Status429TooManyRequests => Status429TooManyRequests, - StatusCodes.Status431RequestHeaderFieldsTooLarge => Status431RequestHeaderFieldsTooLarge, - StatusCodes.Status451UnavailableForLegalReasons => Status451UnavailableForLegalReasons, - StatusCodes.Status500InternalServerError => Status500InternalServerError, - StatusCodes.Status501NotImplemented => Status501NotImplemented, - StatusCodes.Status502BadGateway => Status502BadGateway, - StatusCodes.Status503ServiceUnavailable => Status503ServiceUnavailable, - StatusCodes.Status504GatewayTimeout => Status504GatewayTimeout, - StatusCodes.Status505HttpVersionNotsupported => Status505HttpVersionNotsupported, - StatusCodes.Status506VariantAlsoNegotiates => Status506VariantAlsoNegotiates, - StatusCodes.Status507InsufficientStorage => Status507InsufficientStorage, - StatusCodes.Status508LoopDetected => Status508LoopDetected, - StatusCodes.Status510NotExtended => Status510NotExtended, - StatusCodes.Status511NetworkAuthenticationRequired => Status511NetworkAuthenticationRequired, - _ => new StatusCodeHttpResult(statusCode), - }; - } -} diff --git a/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt b/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt deleted file mode 100644 index 2ad1b0759c14..000000000000 --- a/src/Http/Http.Results/src/ResultsCache.StatusCodes.tt +++ /dev/null @@ -1,98 +0,0 @@ -<#@ template debug="true" hostspecific="true" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ output extension=".cs" #> -<# - /// A collection of constants for - /// HTTP status codes. - var statusCodes = new[] - { - new { StatusCode = 100, Name = "100Continue"}, - new { StatusCode = 101, Name = "101SwitchingProtocols"}, - new { StatusCode = 102, Name = "102Processing"}, - new { StatusCode = 200, Name = "200OK"}, - new { StatusCode = 201, Name = "201Created"}, - new { StatusCode = 202, Name = "202Accepted"}, - new { StatusCode = 203, Name = "203NonAuthoritative"}, - new { StatusCode = 204, Name = "204NoContent"}, - new { StatusCode = 205, Name = "205ResetContent"}, - new { StatusCode = 206, Name = "206PartialContent"}, - new { StatusCode = 207, Name = "207MultiStatus"}, - new { StatusCode = 208, Name = "208AlreadyReported"}, - new { StatusCode = 226, Name = "226IMUsed"}, - new { StatusCode = 300, Name = "300MultipleChoices"}, - new { StatusCode = 301, Name = "301MovedPermanently"}, - new { StatusCode = 302, Name = "302Found"}, - new { StatusCode = 303, Name = "303SeeOther"}, - new { StatusCode = 304, Name = "304NotModified"}, - new { StatusCode = 305, Name = "305UseProxy"}, - new { StatusCode = 306, Name = "306SwitchProxy"}, - new { StatusCode = 307, Name = "307TemporaryRedirect"}, - new { StatusCode = 308, Name = "308PermanentRedirect"}, - new { StatusCode = 400, Name = "400BadRequest"}, - new { StatusCode = 401, Name = "401Unauthorized"}, - new { StatusCode = 402, Name = "402PaymentRequired"}, - new { StatusCode = 403, Name = "403Forbidden"}, - new { StatusCode = 404, Name = "404NotFound"}, - new { StatusCode = 405, Name = "405MethodNotAllowed"}, - new { StatusCode = 406, Name = "406NotAcceptable"}, - new { StatusCode = 407, Name = "407ProxyAuthenticationRequired"}, - new { StatusCode = 408, Name = "408RequestTimeout"}, - new { StatusCode = 409, Name = "409Conflict"}, - new { StatusCode = 410, Name = "410Gone"}, - new { StatusCode = 411, Name = "411LengthRequired"}, - new { StatusCode = 412, Name = "412PreconditionFailed"}, - new { StatusCode = 413, Name = "413RequestEntityTooLarge"}, - new { StatusCode = 414, Name = "414RequestUriTooLong"}, - new { StatusCode = 415, Name = "415UnsupportedMediaType"}, - new { StatusCode = 416, Name = "416RequestedRangeNotSatisfiable"}, - new { StatusCode = 417, Name = "417ExpectationFailed"}, - new { StatusCode = 418, Name = "418ImATeapot"}, - new { StatusCode = 419, Name = "419AuthenticationTimeout"}, - new { StatusCode = 421, Name = "421MisdirectedRequest"}, - new { StatusCode = 422, Name = "422UnprocessableEntity"}, - new { StatusCode = 423, Name = "423Locked"}, - new { StatusCode = 424, Name = "424FailedDependency"}, - new { StatusCode = 426, Name = "426UpgradeRequired"}, - new { StatusCode = 428, Name = "428PreconditionRequired"}, - new { StatusCode = 429, Name = "429TooManyRequests"}, - new { StatusCode = 431, Name = "431RequestHeaderFieldsTooLarge"}, - new { StatusCode = 451, Name = "451UnavailableForLegalReasons"}, - new { StatusCode = 500, Name = "500InternalServerError"}, - new { StatusCode = 501, Name = "501NotImplemented"}, - new { StatusCode = 502, Name = "502BadGateway"}, - new { StatusCode = 503, Name = "503ServiceUnavailable"}, - new { StatusCode = 504, Name = "504GatewayTimeout"}, - new { StatusCode = 505, Name = "505HttpVersionNotsupported"}, - new { StatusCode = 506, Name = "506VariantAlsoNegotiates"}, - new { StatusCode = 507, Name = "507InsufficientStorage"}, - new { StatusCode = 508, Name = "508LoopDetected"}, - new { StatusCode = 510, Name = "510NotExtended"}, - new { StatusCode = 511, Name = "511NetworkAuthenticationRequired"}, - }; -#> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -namespace Microsoft.AspNetCore.Http; - -using System.CodeDom.Compiler; - -[GeneratedCode("TextTemplatingFileGenerator", "")] -internal static partial class ResultsCache -{ -<# foreach (var statusCode in statusCodes) { #> - private static readonly StatusCodeHttpResult Status<#= statusCode.Name #> = new StatusCodeHttpResult(StatusCodes.Status<#= statusCode.Name #>); -<# } #> - - internal static StatusCodeHttpResult StatusCode(int statusCode) - { - return statusCode switch - { -<# foreach (var statusCode in statusCodes) { #> - StatusCodes.Status<#= statusCode.Name #> => Status<#= statusCode.Name #>, -<# } #> - _ => new StatusCodeHttpResult(statusCode), - }; - } -} diff --git a/src/Http/Http.Results/src/ResultsCache.cs b/src/Http/Http.Results/src/ResultsCache.cs deleted file mode 100644 index 0137f6b699d4..000000000000 --- a/src/Http/Http.Results/src/ResultsCache.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.AspNetCore.Http; - -internal static partial class ResultsCache -{ - public static NotFoundObjectHttpResult NotFound { get; } = new(); - public static UnauthorizedHttpResult Unauthorized { get; } = new(); - public static BadRequestObjectHttpResult BadRequest { get; } = new(); - public static ConflictObjectHttpResult Conflict { get; } = new(); - public static NoContentHttpResult NoContent { get; } = new(); - public static OkObjectHttpResult Ok { get; } = new(); - public static UnprocessableEntityObjectHttpResult UnprocessableEntity { get; } = new(); -} diff --git a/src/Http/Http.Results/test/EmptyResultTest.cs b/src/Http/Http.Results/test/EmptyResultTest.cs index b8dd30d4dfff..ef3d787ec8b1 100644 --- a/src/Http/Http.Results/test/EmptyResultTest.cs +++ b/src/Http/Http.Results/test/EmptyResultTest.cs @@ -11,7 +11,7 @@ public class EmptyResultTest public async Task EmptyResult_DoesNothing() { // Arrange - var emptyResult = EmptyHttpResult.Instance; + var emptyResult = new EmptyHttpResult(); // Act var httpContext = GetHttpContext(); From 79310913df517333439134c280b63eba32aaf2c8 Mon Sep 17 00:00:00 2001 From: Bruno Lins de Oliveira Date: Mon, 4 Apr 2022 13:32:58 -0700 Subject: [PATCH 6/6] Updating based on the API proposal --- src/Http/Http.Results/src/ForbidHttpResult.cs | 12 +++--------- src/Http/Http.Results/src/PublicAPI.Unshipped.txt | 6 ++---- src/Http/Http.Results/src/SignOutHttpResult.cs | 12 +++--------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/Http/Http.Results/src/ForbidHttpResult.cs b/src/Http/Http.Results/src/ForbidHttpResult.cs index 0f8e4b8eff44..c32f04e8fb4a 100644 --- a/src/Http/Http.Results/src/ForbidHttpResult.cs +++ b/src/Http/Http.Results/src/ForbidHttpResult.cs @@ -13,21 +13,15 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class ForbidHttpResult : IResult { - /// - /// Initializes a new instance of with the default sign out scheme. - /// - public ForbidHttpResult() - : this(properties: null, authenticationSchemes: Array.Empty()) - { - } - /// /// Initializes a new instance of with the /// specified . /// /// used to perform the authentication /// challenge. - public ForbidHttpResult(AuthenticationProperties? properties) +#pragma warning disable RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. + public ForbidHttpResult(AuthenticationProperties? properties = null) +#pragma warning restore RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. : this(properties, authenticationSchemes: Array.Empty()) { } diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index a67283f9c93c..12b910829063 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -85,8 +85,7 @@ Microsoft.AspNetCore.Http.FileStreamHttpResult.LastModified.init -> void Microsoft.AspNetCore.Http.ForbidHttpResult Microsoft.AspNetCore.Http.ForbidHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! Microsoft.AspNetCore.Http.ForbidHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult() -> void -Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null) -> void Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void Microsoft.AspNetCore.Http.ForbidHttpResult.ForbidHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.ForbidHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? @@ -180,8 +179,7 @@ Microsoft.AspNetCore.Http.SignOutHttpResult Microsoft.AspNetCore.Http.SignOutHttpResult.AuthenticationSchemes.get -> System.Collections.Generic.IReadOnlyList! Microsoft.AspNetCore.Http.SignOutHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.SignOutHttpResult.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties? -Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult() -> void -Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> void +Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties = null) -> void Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, System.Collections.Generic.IList! authenticationSchemes) -> void Microsoft.AspNetCore.Http.SignOutHttpResult.SignOutHttpResult(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string! authenticationScheme) -> void Microsoft.AspNetCore.Http.StatusCodeHttpResult diff --git a/src/Http/Http.Results/src/SignOutHttpResult.cs b/src/Http/Http.Results/src/SignOutHttpResult.cs index ca199cef27f5..fd96db89f790 100644 --- a/src/Http/Http.Results/src/SignOutHttpResult.cs +++ b/src/Http/Http.Results/src/SignOutHttpResult.cs @@ -13,21 +13,15 @@ namespace Microsoft.AspNetCore.Http; /// public sealed partial class SignOutHttpResult : IResult { - /// - /// Initializes a new instance of with the default sign out scheme. - /// - public SignOutHttpResult() - : this(properties: null, authenticationSchemes: Array.Empty()) - { - } - /// /// Initializes a new instance of with the /// specified . /// /// used to perform the authentication /// challenge. - public SignOutHttpResult(AuthenticationProperties? properties) +#pragma warning disable RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. + public SignOutHttpResult(AuthenticationProperties? properties = null) +#pragma warning restore RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads. : this(properties, authenticationSchemes: Array.Empty()) { }