-
Notifications
You must be signed in to change notification settings - Fork 191
Add response trailer feature #1000
Changes from all commits
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,30 @@ | ||||||||||||||||||
// Copyright (c) .NET Foundation. All rights reserved. | ||||||||||||||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||||||||||||
|
||||||||||||||||||
using System; | ||||||||||||||||||
using System.Threading.Tasks; | ||||||||||||||||||
|
||||||||||||||||||
namespace Microsoft.AspNetCore.Http.Features | ||||||||||||||||||
{ | ||||||||||||||||||
public interface IHttpResponseTrailersFeature | ||||||||||||||||||
{ | ||||||||||||||||||
/// <summary> | ||||||||||||||||||
/// The response trailers to send. | ||||||||||||||||||
/// </summary> | ||||||||||||||||||
IHeaderDictionary Trailers { get; set; } | ||||||||||||||||||
|
||||||||||||||||||
/// <summary> | ||||||||||||||||||
/// Indicates if the server has started writing the response trailers. | ||||||||||||||||||
/// If true, the <see cref="Trailers"/> are now immutable, and <see cref="OnStarting"/> should no longer be called. | ||||||||||||||||||
/// </summary> | ||||||||||||||||||
bool HasStarted { get; } | ||||||||||||||||||
|
||||||||||||||||||
/// <summary> | ||||||||||||||||||
/// Registers a callback to be invoked just before writing the response trailers. | ||||||||||||||||||
/// This is the last chance to modify the <see cref="Trailers"/>. | ||||||||||||||||||
/// </summary> | ||||||||||||||||||
/// <param name="callback">The callback to invoke before writing the trailers.</param> | ||||||||||||||||||
/// <param name="state">The state to pass into the callback.</param> | ||||||||||||||||||
void OnStarting(Func<object, Task> callback, object state); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe call this OnWritingResponseTrailers. I get that my suggested name is a little redundant with the name of the interface, but I think the current naming is too similar to IHttpResponseFeature.OnStarting and could cause confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an HttpAbstractions/src/Microsoft.AspNetCore.Http.Features/IHttpResponseFeature.cs Lines 42 to 49 in b85ed9d
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Yes I see what you mean. Shame it wasn't called something more like the owin feature then. Consistency would probably win here. |
||||||||||||||||||
} | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.AspNetCore.Http.Features | ||
{ | ||
public class HttpResponseTrailersFeature : IHttpResponseTrailersFeature | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do you expect to need this implementation? I expect the servers to provide their own. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't. I just saw the other features had "dummy" implementations, so just followed along. |
||
{ | ||
public HttpResponseTrailersFeature() | ||
{ | ||
Trailers = new HeaderDictionary(); | ||
} | ||
|
||
public IHeaderDictionary Trailers { get; set; } | ||
|
||
public virtual bool HasStarted => false; | ||
|
||
public virtual void OnStarting(Func<object, Task> callback, object state) | ||
{ | ||
} | ||
} | ||
} |
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.
WasWritten?
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.
That would indicate that it's set after the trailers has been written? This would be set just before the server starts writing.
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.
I'm not too convinced WasWritten is a better name either.
I proposed WasWritten since the Trailers dictionary is closed for modification and the server has committed to writing what's in the dictionary as trailers at the point this property is set. From the perspective of the app developer, I don't see how committing to writing the trailers is observably different from actually writing the trailers especially given that there's write-behind response buffer.
HasStarted isn't bad though. I was thinking HasStartedWriting to make it less ambiguous, but I suggested WasWritten since that's shorter.
If we decided to change OnStarting to OnStartingTrailers or something similar, we might want to change this to HasStartedTrailers instead.
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.
Agan, I chose
HasStarted
because it's consistent withIHttpResponseFeature.HasStarted
. If we can find another name, or get rid of the property entirely, that's cool with me.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.
IsReadOnly? IHeaderDictionary already has that property, we can probably remove this one.
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.
Why would the trailer dictionary not be mutable? I think I'm missing something in the IsReadOnly commentOk, got it. On the trailer header dictionary. Makes sense.