From ee804e58412278c9d34dc114957ca17c1b248111 Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 22 Dec 2015 16:01:31 -0800 Subject: [PATCH] Register FileBufferingReadStream for disposal --- src/Microsoft.AspNet.Http/BufferingHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Http/BufferingHelper.cs b/src/Microsoft.AspNet.Http/BufferingHelper.cs index e56d73e5cf..03c3db188f 100644 --- a/src/Microsoft.AspNet.Http/BufferingHelper.cs +++ b/src/Microsoft.AspNet.Http/BufferingHelper.cs @@ -48,9 +48,9 @@ namespace Microsoft.AspNet.Http.Internal var body = request.Body; if (!body.CanSeek) { - // TODO: Register this buffer for disposal at the end of the request to ensure the temp file is deleted. - // Otherwise it won't get deleted until GC closes the stream. - request.Body = new FileBufferingReadStream(body, bufferThreshold, _getTempDirectory); + var fileStream = new FileBufferingReadStream(body, bufferThreshold, _getTempDirectory); + request.Body = fileStream; + request.HttpContext.Response.RegisterForDispose(fileStream); } return request; }