本文整理汇总了C#中IHttpContext.SetResponseFilter方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetResponseFilter方法的具体用法?C# IHttpContext.SetResponseFilter怎么用?C# IHttpContext.SetResponseFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetResponseFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdaptHttpContext
private Action AdaptHttpContext(IHttpContext httpContext, ServerLog serverLog)
{
if (pathsToFilter.Contains(httpContext.Request.Url.AbsolutePath))
return null;
if (ignoreHilo && httpContext.Request.Url.AbsolutePath.StartsWith("/docs/Raven/Hilo/"))
return null;
if (httpContext.Request.Headers["Raven-Timer-Request"] != null)
return null;
var requestStream = new MemoryStream();
httpContext.SetRequestFilter(stream =>
{
stream.CopyTo(requestStream);
return new MemoryStream(requestStream.ToArray());
});
var responseStream = new MemoryStream();
httpContext.SetResponseFilter(stream => new MultiStreamWriter(responseStream, stream));
var trackedRequest = new TrackedRequest
{
Method = httpContext.Request.HttpMethod,
Url = httpContext.Request.RawUrl,
RequestHeaders = new NameValueCollection(httpContext.Request.Headers),
RequestContent = requestStream,
ResponseContent = responseStream,
ResponseHeaders = httpContext.Response.GetHeaders(),
};
return () =>
{
trackedRequest.Status = httpContext.Response.StatusCode;
serverLog.AddRequest(trackedRequest);
};
}
示例2: AddHttpCompressionIfClientCanAcceptIt
private static void AddHttpCompressionIfClientCanAcceptIt(IHttpContext ctx)
{
var acceptEncoding = ctx.Request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(acceptEncoding))
return;
// The Studio xap is already a compressed file, it's a waste of time to try to compress it further.
var requestUrl = ctx.GetRequestUrl();
if (String.Equals(requestUrl, "/silverlight/Raven.Studio.xap", StringComparison.OrdinalIgnoreCase))
return;
// gzip must be first, because chrome has an issue accepting deflate data
// when sending it json text
if ((acceptEncoding.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) != -1))
{
ctx.SetResponseFilter(s => new GZipStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) != -1)
{
ctx.SetResponseFilter(s => new DeflateStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "deflate");
}
}
示例3: AddHttpCompressionIfClientCanAcceptIt
private static void AddHttpCompressionIfClientCanAcceptIt(IHttpContext ctx)
{
var acceptEncoding = ctx.Request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(acceptEncoding))
return;
// gzip must be first, because chrome has an issue accepting deflate data
// when sending it json text
if ((acceptEncoding.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) != -1))
{
ctx.SetResponseFilter(s => new GZipStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) != -1)
{
ctx.SetResponseFilter(s => new DeflateStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "deflate");
}
}