JSON

权威课程:dubbo,Zookeeper,solr,scala,netty,Hadoop,数据(3)

字号+ 作者:H5之家 来源:H5之家 2016-11-06 12:00 我要评论( )

public class CompressContent : HttpContent{ _encodingType; private readonly HttpContent _originalContent; ){_originalContent = content;_encodingType = encodingType.ToLowerInvariant();Headers.ContentE

public class CompressContent : HttpContent { _encodingType; private readonly HttpContent _originalContent; ) { _originalContent = content; _encodingType = encodingType.ToLowerInvariant(); Headers.ContentEncoding.Add(encodingType); } TryComputeLength(out long length) { length = -1; return false; } protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { Stream compressStream = null; switch (_encodingType) { : compressStream = new GZipStream(stream, CompressionMode.Compress, true); break; : compressStream = new DeflateStream(stream, CompressionMode.Compress, true); break; default: compressStream = stream; break; } return _originalContent.CopyToAsync(compressStream).ContinueWith(tsk => { if (compressStream != null) { compressStream.Dispose(); } }); } }

重写过滤器特性

public class CompressContentAttribute : ActionFilterAttribute { OnActionExecuted(HttpActionExecutedContext context) { var acceptedEncoding = context.Response.RequestMessage.Headers.AcceptEncoding.First().Value; , StringComparison.InvariantCultureIgnoreCase) && !acceptedEncoding.Equals(, StringComparison.InvariantCultureIgnoreCase)) {

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 叶玲童鞋的课程

    叶玲童鞋的课程

    2015-11-23 12:17

  • 梅姐偶尔冒个泡的课程

    梅姐偶尔冒个泡的课程

    2015-11-18 13:56

  • Dubbo视频教程--基础篇--第06节--Dubbo管理控制台的安装

    Dubbo视频教程--基础篇--第06节--Dubbo管理控制台的安装

    2015-10-16 15:32

  • 0027的课程

    0027的课程

    2015-10-14 15:23

网友点评