当前位置: 首页>>代码示例>>C#>>正文


C# IHttpContext.SetRequestFilter方法代码示例

本文整理汇总了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);
            };
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:Shell.cs

示例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));
			}
		}
开发者ID:urbanfly,项目名称:ravendb,代码行数:15,代码来源:HttpServer.cs


注:本文中的IHttpContext.SetRequestFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。