diff --git a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs index ca88637dba..16a08b9b3c 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs @@ -13,10 +13,36 @@ namespace MediaBrowser.Common.Net.Handlers /// public IDictionary Headers = new Dictionary(); + /// + /// Returns true or false indicating if the handler writes to the stream asynchronously. + /// If so the subclass will be responsible for disposing the stream when complete. + /// + protected virtual bool IsAsyncHandler + { + get + { + return false; + } + } + /// /// The action to write the response to the output stream /// - public Action WriteStream { get; set; } + public virtual Action WriteStream + { + get + { + return s => + { + WriteReponse(s); + + if (!IsAsyncHandler) + { + s.Dispose(); + } + }; + } + } /// /// The original RequestContext @@ -81,15 +107,6 @@ namespace MediaBrowser.Common.Net.Handlers } } - public BaseHandler() - { - WriteStream = s => - { - WriteReponse(s); - s.Dispose(); - }; - } - private void WriteReponse(Stream stream) { if (CompressResponse)