处置响应过滤器的责任

时间:2013-02-22 02:13:38

标签: asp.net-mvc filter decorator

背景

我正在考虑整合CompressFilter来自

Removing extra whitespace from generated HTML in MVC

进入我自己的代码。在此之前,我想测量CompressFilter中花费的时间。自从我cannot use the Visual Studio Profiler以来,我决定创建一个简单的流包装器

private class BenchmarkStream : Stream
{
    Stream inner;

    public BenchmarkStream(Stream inner)
    {
        if (inner == null) throw new ArgumentException("inner");
        this.inner = inner;
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
        Stopwatch sw = Stopwatch.StartNew();
        inner.Write(buffer, offset, count);
        sw.Stop();
        Debug.WriteLine("Compressed " + count + " bytes in " + 
           sw.ElapsedMilliseconds + "ms");
    }
    // Rest of implementation removed for brevity
}

一样使用
response.Filter = new BenchmarkStream(
                    new GZipStream(response.Filter, CompressionMode.Compress));

问题

我是否负责处理我的流inner或ASP.Net运行时是否有机制这样做?

CompressFilter的代码未明确处理分配给GZipStream的{​​{1}}或DeflateStream,但我看不到运行时如何处理response.Filter }}。

我是否正确地假设innerGZipStream负责处理它所组成的流?

0 个答案:

没有答案