-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make IResults types public #40704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make IResults types public #40704
Changes from 13 commits
0ab4de9
813786e
811c604
5d66c24
acf0a3b
9ddf586
9a79b02
a1fef75
1ee3138
2c029a8
4103a0f
5fdebc4
6146e4a
7d89ce3
6171f15
6a807cf
5fa233d
dcf745b
3d01bb6
e05b04f
9c628aa
eada9b4
ff3cb76
00877b5
825f4c0
73800b9
8fb15dd
dac8711
4a50104
1d76b6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // 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.Threading.Tasks; | ||
|
|
||
| /// <summary> | ||
| /// An <see cref="IResult"/> that on execution will write an object to the response | ||
| /// with status code Accepted (202) and Location header. | ||
| /// Targets a registered route. | ||
| /// </summary> | ||
| public sealed class AcceptedHttpResult : IResult | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AcceptedHttpResult"/> class with the values | ||
| /// provided. | ||
| /// </summary> | ||
| /// <param name="location">The location at which the status of requested content can be monitored.</param> | ||
| /// <param name="value">The value to format in the entity body.</param> | ||
| public AcceptedHttpResult(string? location, object? value) | ||
| { | ||
| Value = value; | ||
| Location = location; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AcceptedHttpResult"/> class with the values | ||
| /// provided. | ||
| /// </summary> | ||
| /// <param name="locationUri">The location at which the status of requested content can be monitored.</param> | ||
| /// <param name="value">The value to format in the entity body.</param> | ||
| public AcceptedHttpResult(Uri locationUri, object? value) | ||
| { | ||
| Value = value; | ||
|
|
||
| if (locationUri == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(locationUri)); | ||
| } | ||
|
|
||
| if (locationUri.IsAbsoluteUri) | ||
| { | ||
| Location = locationUri.AbsoluteUri; | ||
| } | ||
| else | ||
| { | ||
| Location = locationUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public object? Value { get; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public int StatusCode => StatusCodes.Status202Accepted; | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? Location { get; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Task ExecuteAsync(HttpContext httpContext) | ||
| { | ||
| return HttpResultsWriter.WriteResultAsJsonAsync( | ||
| httpContext, | ||
| Value, | ||
| StatusCode, | ||
| configureResponseHeader: (context) => | ||
| { | ||
| if (!string.IsNullOrEmpty(Location)) | ||
| { | ||
| context.Response.Headers.Location = Location; | ||
| } | ||
| }); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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; | ||
|
|
||
| /// <summary> | ||
| /// An <see cref="IResult"/> that on execution will write an object to the response | ||
| /// with Bad Request (400) status code. | ||
| /// </summary> | ||
| public sealed class BadRequestObjectHttpResult : IResult | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="BadRequestObjectHttpResult"/> class with the values | ||
| /// provided. | ||
| /// </summary> | ||
| /// <param name="error">The error content to format in the entity body.</param> | ||
| public BadRequestObjectHttpResult(object? error) | ||
| { | ||
| Value = error; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public object? Value { get; internal init; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public int StatusCode => StatusCodes.Status400BadRequest; | ||
|
|
||
| /// <inheritdoc/> | ||
| public Task ExecuteAsync(HttpContext httpContext) | ||
| => HttpResultsWriter.WriteResultAsJsonAsync(httpContext, Value, StatusCode); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,84 +6,91 @@ | |||||
| using Microsoft.Extensions.DependencyInjection; | ||||||
| using Microsoft.Extensions.Logging; | ||||||
|
|
||||||
| namespace Microsoft.AspNetCore.Http.Result; | ||||||
| namespace Microsoft.AspNetCore.Http; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// An <see cref="IResult"/> that on execution invokes <see cref="M:HttpContext.ChallengeAsync"/>. | ||||||
| /// </summary> | ||||||
| internal sealed partial class ChallengeResult : IResult | ||||||
| public sealed partial class ChallengeHttpResult : IResult | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/>. | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/>. | ||||||
| /// </summary> | ||||||
| public ChallengeResult() | ||||||
| public ChallengeHttpResult() | ||||||
| : this(Array.Empty<string>()) | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/> with the | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/> with the | ||||||
| /// specified authentication scheme. | ||||||
| /// </summary> | ||||||
| /// <param name="authenticationScheme">The authentication scheme to challenge.</param> | ||||||
| public ChallengeResult(string authenticationScheme) | ||||||
| public ChallengeHttpResult(string authenticationScheme) | ||||||
| : this(new[] { authenticationScheme }) | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/> with the | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/> with the | ||||||
| /// specified authentication schemes. | ||||||
| /// </summary> | ||||||
| /// <param name="authenticationSchemes">The authentication schemes to challenge.</param> | ||||||
| public ChallengeResult(IList<string> authenticationSchemes) | ||||||
| public ChallengeHttpResult(IList<string> authenticationSchemes) | ||||||
| : this(authenticationSchemes, properties: null) | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/> with the | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/> with the | ||||||
| /// specified <paramref name="properties"/>. | ||||||
| /// </summary> | ||||||
| /// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the authentication | ||||||
| /// challenge.</param> | ||||||
| public ChallengeResult(AuthenticationProperties? properties) | ||||||
| public ChallengeHttpResult(AuthenticationProperties? properties) | ||||||
| : this(Array.Empty<string>(), properties) | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/> with the | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/> with the | ||||||
| /// specified authentication scheme and <paramref name="properties"/>. | ||||||
| /// </summary> | ||||||
| /// <param name="authenticationScheme">The authentication schemes to challenge.</param> | ||||||
| /// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the authentication | ||||||
| /// challenge.</param> | ||||||
| public ChallengeResult(string authenticationScheme, AuthenticationProperties? properties) | ||||||
| public ChallengeHttpResult(string authenticationScheme, AuthenticationProperties? properties) | ||||||
| : this(new[] { authenticationScheme }, properties) | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Initializes a new instance of <see cref="ChallengeResult"/> with the | ||||||
| /// Initializes a new instance of <see cref="ChallengeHttpResult"/> with the | ||||||
| /// specified authentication schemes and <paramref name="properties"/>. | ||||||
| /// </summary> | ||||||
| /// <param name="authenticationSchemes">The authentication scheme to challenge.</param> | ||||||
| /// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the authentication | ||||||
| /// challenge.</param> | ||||||
| public ChallengeResult(IList<string> authenticationSchemes, AuthenticationProperties? properties) | ||||||
| public ChallengeHttpResult(IList<string> authenticationSchemes, AuthenticationProperties? properties) | ||||||
| { | ||||||
| AuthenticationSchemes = authenticationSchemes; | ||||||
| AuthenticationSchemes = authenticationSchemes.AsReadOnly(); | ||||||
| Properties = properties; | ||||||
| } | ||||||
|
|
||||||
| public IList<string> AuthenticationSchemes { get; init; } = Array.Empty<string>(); | ||||||
| /// <summary> | ||||||
| /// Gets or sets the authentication schemes that are challenged. | ||||||
| /// </summary> | ||||||
| public IReadOnlyList<string> AuthenticationSchemes { get; internal init; } = Array.Empty<string>(); | ||||||
|
|
||||||
| public AuthenticationProperties? Properties { get; init; } | ||||||
| /// <summary> | ||||||
| /// Gets or sets the <see cref="AuthenticationProperties"/> used to perform the sign-out operation. | ||||||
| /// </summary> | ||||||
| public AuthenticationProperties? Properties { get; internal init; } | ||||||
|
|
||||||
| /// <inheritdoc/> | ||||||
| public async Task ExecuteAsync(HttpContext httpContext) | ||||||
| { | ||||||
| var logger = httpContext.RequestServices.GetRequiredService<ILogger<ChallengeResult>>(); | ||||||
| var logger = httpContext.RequestServices.GetRequiredService<ILogger<ChallengeHttpResult>>(); | ||||||
|
||||||
| // We create the logger with a string to preserve the logging namespace after the server side transport renames. | |
| _logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, i think we should not change the categories. I have pushed a commit following @BrennanConroy example.
@halter73 / @BrennanConroy can you do a quick review? 00877b5
Uh oh!
There was an error while loading. Please reload this page.