本文整理汇总了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
}