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


C# IPipelines.EnableGzipCompression方法代码示例

本文整理汇总了C#中IPipelines.EnableGzipCompression方法的典型用法代码示例。如果您正苦于以下问题:C# IPipelines.EnableGzipCompression方法的具体用法?C# IPipelines.EnableGzipCompression怎么用?C# IPipelines.EnableGzipCompression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPipelines的用法示例。


在下文中一共展示了IPipelines.EnableGzipCompression方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestStartup

        /// <summary>
        /// This function override the RequestStartup which is used each time a request came to Nancy
        /// </summary>
        protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
        {
            var configuration =
                new StatelessAuthenticationConfiguration(nancyContext =>
                {
                    //try to take "apikey" from header
                    string apiKey = nancyContext.Request.Headers["apikey"].FirstOrDefault();
                    if (string.IsNullOrEmpty(apiKey))
                    {
                        //take out value of "apikey" from query that was pass in request and check for User
                        apiKey = (string)nancyContext.Request.Query.apikey.Value;
                    }
                    if (apiKey != null)
                    {
                        return UserDatabase.GetUserFromApiKey(apiKey);
                    }
                    else
                    {
                        return null;
                    }
                });
            StaticConfiguration.DisableErrorTraces = false;
            StatelessAuthentication.Enable(pipelines, configuration);

            pipelines.OnError += (NancyContext ctx, Exception ex) => onError(ctx, ex);

            pipelines.BeforeRequest += (NancyContext ctx) => BeforeProcessing(ctx);
            pipelines.AfterRequest += (NancyContext ctx) => AfterProcessing(ctx);

            #region CORS Enable
            pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
            {
                ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
                                .WithHeader("Access-Control-Allow-Methods", "POST,GET")
                                .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");

            });
            #endregion

            #region Gzip compression
            GzipCompressionSettings gzipsettings = new GzipCompressionSettings();
            gzipsettings.MinimumBytes = 16384; //16k
            gzipsettings.MimeTypes.Add("application/xml");
            gzipsettings.MimeTypes.Add("application/json");
            pipelines.EnableGzipCompression(gzipsettings);
            #endregion
        }
开发者ID:japanesemediamanager,项目名称:jmmserver,代码行数:50,代码来源:Bootstrapper.cs


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