Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Add a notification for when the request is completed #160

Closed
Tratcher opened this issue Jan 9, 2015 · 0 comments
Closed

Add a notification for when the request is completed #160

Tratcher opened this issue Jan 9, 2015 · 0 comments

Comments

@Tratcher
Copy link
Member

Tratcher commented Jan 9, 2015

Some resources need to be cleaned up at the end of a request. Middleware can do this as the request pipeline unwinds. Non-middleware components do not have a clear indication of when they should clean up their resources and must currently rely on the GC.

Example:
https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/BufferingHelper.cs#L40
When the request body is buffered to a temp file it is marked as delete-on-close. However, it's unclear when the temp buffer is actually ready for disposal so the GC has to take care of it. The code above could register for a new notification that the request had ended and proactively dispose the temp file at that point.

Prior art: Right now we have an notification void HttpResponse.OnSendingHeaders(Action<object> callback, object state) where components can register for callbacks to be invoked just before the response headers are sent.

Proposal: void HttpResponse.OnResponseCompleted(Action<object> callback, object state)
Semantics: Registered callbacks are invoked after the response has complete and the application pipeline has unwound. The HttpContext is still in scope and may be used as part of the state parameter but it is too late to make any modifications to the response.

Should this go on the IHttpResposneFeature interface next to OnSendingHeaders?

@Tratcher Tratcher added this to the Backlog milestone Jan 21, 2015
ajaybhargavb added a commit to aspnet/Hosting that referenced this issue Mar 16, 2015
ajaybhargavb added a commit to aspnet/KestrelHttpServer that referenced this issue Mar 16, 2015
ajaybhargavb added a commit to aspnet/Hosting that referenced this issue Mar 17, 2015
ajaybhargavb added a commit to aspnet/HttpSysServer that referenced this issue Mar 17, 2015
ajaybhargavb added a commit to aspnet/Hosting that referenced this issue Mar 18, 2015
@ajaybhargavb ajaybhargavb modified the milestones: 1.0.0-beta4, Backlog Apr 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants