如何支持COM pressed HTTP请求Asp.Net 4.0 / IIS7? [英] How to support compressed HTTP requests in Asp.Net 4.0 / IIS7?

查看:107
本文介绍了如何支持COM pressed HTTP请求Asp.Net 4.0 / IIS7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于ASP.NET 4.0 / IIS7 web应用程序,我想支持COM pressed HTTP 要求。基本上,我想支持的客户,将增加内容编码:gzip的的请求头,和COM preSS身体相应

For an ASP.NET 4.0 / IIS7 web app, I would like to support compressed HTTP requests. Basically, I would like to support clients that would add Content-Encoding: gzip in the request headers, and compress the body accordingly.

有谁知我如何实现这样的行为?

Does anyone known how I achieve such a behavior?

诗:关于我有多个端点REST和SOAP,而且感觉更好的解决方案,支持在HTTP级COM pression,而不是定制的连接codeRS为每个端点

Ps: concerning, I have multiple endpoints REST and SOAP, and it feels a better solution to support compression at the HTTP level rather than custom encoders for each endpoint.

推荐答案

对于那些谁可能会感兴趣,实现相当简单与 IHttpModule的,简单地过滤传入的请求

For those who might be interested, the implementation is rather straightforward with an IHttpModule that simply filters incoming requests.

public class GZipDecompressModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += BeginRequest;
    }

    void BeginRequest(object sender, EventArgs e)
    {
        var app = (HttpApplication)sender;

        if ("gzip" == app.Request.Headers["Content-Encoding"])
        {
            app.Request.Filter = new GZipStream(
               app.Request.Filter, CompressionMode.Decompress);
        }
    }

    public void Dispose()
    {
    }
}

更新:看来,这种做法在WCF中引发问题,因为WCF依赖于原始的的Content-Length ,而不是得到的值后DECOM pressing。

Update: It appears that this approach trigger a problem in WCF, as WCF relies on the original Content-Length and not the value obtained after decompressing.

这篇关于如何支持COM pressed HTTP请求Asp.Net 4.0 / IIS7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆