Skip to content

Conversation

@pranavkm
Copy link
Contributor

  • Add Results.Bytes, Results.Stream, and Results.Text overloads.
  • Consolidate Physical and Virtual files helpers.
  • Use default arguments to consolidate overloads.
  • Remove Accepted(Uri?) / Accepted(Uri?, object? value) overload to remove ambiguity with AcceptedAt(string?, object? value);

* Add Results.Bytes, Results.Stream, and Results.Text overloads.
* Consolidate Physical and Virtual files helpers.
* Use default arguments to consolidate overloads.
* Remove Accepted(Uri?) / Accepted(Uri?, object? value) overload to remove ambiguity with AcceptedAt(string?, object? value);
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName, object? routeValues) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName, object? routeValues, object? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Accepted(string? uri = null, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Accepted(System.Uri! uri)? Are we saying just use Uri.ToString()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally like less overloads for now. If people really want this, we can add the overload later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can call ToString 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uri.AbsoulteUri, never use ToString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code does AbsoluteUri and other strange things for non-absolute uris: https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/AcceptedResult.cs#L56-L63. But yeah, people could just write that code.

static Microsoft.AspNetCore.Http.Results.Content(string! content, string! contentType) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Content(string! content, string! contentType, System.Text.Encoding! contentEncoding) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Content(string! content, Microsoft.Net.Http.Headers.MediaTypeHeaderValue! contentType) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Content(string! content, string? contentType = null, System.Text.Encoding? contentEncoding = null) -> Microsoft.AspNetCore.Http.IResult!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we feel about just keeping Text and removing the Content overloads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't have a strong sense for how commonly this result type is used. That said, the reasons to keep it would be compat with MVC (portability / muscle memory) which might be enough of a tipping point.

/// <summary>
/// Writes the <paramref name="content"/> string to the HTTP response.
/// <para>
/// This is an alias for <see cref="Text(string, string?, Encoding?)"/>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to ignore precedence and only have Text/Stream?

Copy link
Contributor

@JunTaoLuo JunTaoLuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When tests pass.

return new ContentResult
{
Content = content,
ContentType = mediaTypeHeaderValue?.ToString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we ToString after Parsing? Validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We kinda only want the string representation to set the response header. The parsing allows us to overwrite any existing encoding with the value specified.

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.MapGet("/blob", (BlobServiceClient client) => 
{
    BlobClient blob = client.GetBlobContainerClient("container").GetBlobClient("blob");
    return Results.Stream((stream, cancellationToken) => blob.DownloadToAsync(stream,  cancellationToken), fileDownloadName: fileName));
});

@pranavkm pranavkm requested a review from javiercn as a code owner July 13, 2021 05:18
@pranavkm
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

}

OnFormatting(httpContext);
if (Value is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this go earlier?

@pranavkm pranavkm requested a review from davidfowl July 13, 2021 20:24
{
var logger = httpContext.RequestServices.GetRequiredService<ILogger<FileStreamResult>>();
using (FileStream)
await using (FileStream)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah hah! That was the bug!

@halter73
Copy link
Member

Do we need a status code option for Text/Bytes/Stream?

I don't think so. I think 200 responses are the 99% case, and you can manually set the status on the HttpResponse if you want to

@pranavkm pranavkm enabled auto-merge (squash) July 13, 2021 22:49
@davidfowl
Copy link
Member

I don't get why this PR is making the blazor wasm tests fail:

/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/Data/ApplicationDbContext.cs(4,7): error CS0246: The type or namespace name 'IdentityServer4' could not be found (are you missing a using directive or an assembly reference?) [/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/AspNet.qmmkzui22qe.Server.csproj]
/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/Data/ApplicationDbContext.cs(13,22): error CS0246: The type or namespace name 'OperationalStoreOptions' could not be found (are you missing a using directive or an assembly reference?) [/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/AspNet.qmmkzui22qe.Server.csproj]/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/Data/ApplicationDbContext.cs(4,7): error CS0246: The type or namespace name 'IdentityServer4' could not be found (are you missing a using directive or an assembly reference?) [/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/AspNet.qmmkzui22qe.Server.csproj]
/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/Data/ApplicationDbContext.cs(13,22): error CS0246: The type or namespace name 'OperationalStoreOptions' could not be found (are you missing a using directive or an assembly reference?) [/datadisks/disk1/work/A9DC0913/w/C4540A6A/e/Templates/BaseFolder/AspNet.qmmkzui22qe/Server/AspNet.qmmkzui22qe.Server.csproj]

@davidfowl
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@davidfowl
Copy link
Member

Seems like it was this #34317

@dougbu
Copy link
Contributor

dougbu commented Jul 14, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@pranavkm pranavkm merged commit 837b178 into main Jul 14, 2021
@pranavkm pranavkm deleted the prkrishn/results-cleanup branch July 14, 2021 06:23
@ghost ghost added this to the 6.0-preview7 milestone Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants