-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Merged
brunolins16
merged 30 commits into
dotnet:main
from
brunolins16:brunolins16/iresult-apisuggestion
Mar 20, 2022
Merged
Make IResults types public #40704
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0ab4de9
StatuCodeResult as base class
brunolins16 813786e
StatuCodeResult as base class
brunolins16 811c604
Making types public and renaming to HTTPResult
brunolins16 5d66c24
Update comments
brunolins16 acf0a3b
Make setters internal
brunolins16 9ddf586
Updating public API file
brunolins16 9a79b02
Removing base classes
brunolins16 a1fef75
Changing method name to WriteResultAsStatusCode
brunolins16 1ee3138
Updating API
brunolins16 2c029a8
code cleanup
brunolins16 4103a0f
fixing public api
brunolins16 5fdebc4
Simplyfing interfaces
brunolins16 6146e4a
Removing interfaces + Adding ctors
brunolins16 7d89ce3
Fixing xml docs
brunolins16 6171f15
Making EmptyResult public
brunolins16 6a807cf
Updating JsonHttpResult
brunolins16 5fa233d
Adding missing ctor
brunolins16 dcf745b
Adding missing ctor
brunolins16 3d01bb6
Adding missing ctor
brunolins16 e05b04f
Adding misssed xml comment
brunolins16 9c628aa
Removing configureResponseHeader
brunolins16 eada9b4
PR Feedback
brunolins16 ff3cb76
Moving ctors to internal
brunolins16 00877b5
Create logger using string category
brunolins16 825f4c0
Adding more unittests
brunolins16 73800b9
Update src/Http/Http.Results/src/EmptyHttpResult.cs
brunolins16 8fb15dd
Update ContentHttpResult.cs
brunolins16 dac8711
avoid closure allocation
brunolins16 4a50104
Merge branch 'brunolins16/iresult-apisuggestion' of https://github.co…
brunolins16 1d76b6e
unit loggerfactory
brunolins16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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> | ||
/// Defines a contract that represents the result of an HTTP result endpoint | ||
/// that constains an <see cref="Location"/>. | ||
/// </summary> | ||
public interface IAtLocationHttpResult : IResult | ||
{ | ||
/// <summary> | ||
/// Gets the location at which the status of the requested content can be monitored. | ||
/// </summary> | ||
string? Location { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Defines a contract that represents the result of an HTTP result endpoint | ||
/// that constains an object route. | ||
/// </summary> | ||
public interface IAtRouteHttpResult : IResult | ||
{ | ||
/// <summary> | ||
/// Gets the name of the route to use for generating the URL. | ||
/// </summary> | ||
string? RouteName { get; } | ||
|
||
/// <summary> | ||
/// Gets the route data to use for generating the URL. | ||
/// </summary> | ||
RouteValueDictionary? RouteValues { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Net.Http.Headers; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Defines a contract that represents the file result of an HTTP result endpoint. | ||
/// </summary> | ||
public interface IFileHttpResult : IResult | ||
{ | ||
/// <summary> | ||
/// Gets the Content-Type header for the response. | ||
/// </summary> | ||
string ContentType { get; } | ||
|
||
/// <summary> | ||
/// Gets the file name that will be used in the Content-Disposition header of the response. | ||
/// </summary> | ||
string? FileDownloadName { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the last modified information associated with the <see cref="IFileHttpResult"/>. | ||
/// </summary> | ||
DateTimeOffset? LastModified { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the etag associated with the <see cref="IFileHttpResult"/>. | ||
/// </summary> | ||
EntityTagHeaderValue? EntityTag { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the value that enables range processing for the <see cref="IFileHttpResult"/>. | ||
/// </summary> | ||
bool EnableRangeProcessing { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the file length information associated with the <see cref="IFileHttpResult"/>. | ||
/// </summary> | ||
long? FileLength { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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> | ||
/// Defines a contract that represents the result of an HTTP endpoint | ||
/// that contains an object <see cref="Value"/> and a given statu code. | ||
/// </summary> | ||
public interface IObjectHttpResult : IResult, IStatusCodeHttpResult | ||
{ | ||
/// <summary> | ||
/// Gets or sets the object result. | ||
/// </summary> | ||
object? Value { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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> | ||
/// Defines a contract that represents the HTTP Redirect result of an HTTP result endpoint. | ||
/// </summary> | ||
public interface IRedirectHttpResult : IResult | ||
{ | ||
/// <summary> | ||
/// Gets the value that specifies that the redirect should be permanent if true or temporary if false. | ||
/// </summary> | ||
bool Permanent { get; } | ||
|
||
/// <summary> | ||
/// Gets an indication that the redirect preserves the initial request method. | ||
/// </summary> | ||
bool PreserveMethod { get; } | ||
|
||
/// <summary> | ||
/// Gets the URL to redirect to. | ||
/// </summary> | ||
string? Url { get; } | ||
|
||
/// <summary> | ||
/// Gets an indication that only local URLs are accepted. | ||
/// </summary> | ||
bool AcceptLocalUrlOnly { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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> | ||
/// Defines a contract that represents the result of an HTTP endpoint | ||
/// that contains a <see cref="StatusCode"/>. | ||
/// </summary> | ||
public interface IStatusCodeHttpResult : IResult | ||
{ | ||
/// <summary> | ||
/// Gets or sets the HTTP status code. | ||
/// </summary> | ||
int? StatusCode { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 29 additions & 18 deletions
47
...Http.Results/src/AcceptedAtRouteResult.cs → ....Results/src/AcceptedAtRouteHttpResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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, IObjectHttpResult, IStatusCodeHttpResult, IAtLocationHttpResult | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AcceptedHttpResult"/> class with the values | ||
/// provided. | ||
/// </summary> | ||
internal AcceptedHttpResult() | ||
{ | ||
} | ||
|
||
/// <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> | ||
internal 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> | ||
internal 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) | ||
=> HttpResultsWriter.WriteResultAsJson(httpContext, objectHttpResult: this, configureResponseHeader: ConfigureResponseHeaders); | ||
|
||
private void ConfigureResponseHeaders(HttpContext context) | ||
{ | ||
if (!string.IsNullOrEmpty(Location)) | ||
{ | ||
context.Response.Headers.Location = Location; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.