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


C# IHttpContext.SetResponseFilter方法代码示例

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

示例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");
			}

		}
开发者ID:urbanfly,项目名称:ravendb,代码行数:26,代码来源:HttpServer.cs

示例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");
			}

		}
开发者ID:csainty,项目名称:ravendb,代码行数:21,代码来源:HttpServer.cs


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