Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
This repository was 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

Description

@Tratcher

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions