本文整理汇总了C#中IHttpContext.SetRequestFilter方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetRequestFilter方法的具体用法?C# IHttpContext.SetRequestFilter怎么用?C# IHttpContext.SetRequestFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetRequestFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: HandleHttpCompressionFromClient
private static void HandleHttpCompressionFromClient(IHttpContext ctx)
{
var encoding = ctx.Request.Headers["Content-Encoding"];
if (encoding == null)
return;
if (encoding.Contains("gzip"))
{
ctx.SetRequestFilter(stream => new GZipStream(stream, CompressionMode.Decompress));
}
else if (encoding.Contains("deflate"))
{
ctx.SetRequestFilter(stream => new DeflateStream(stream, CompressionMode.Decompress));
}
}