IIS application missing Content-Encoding - gzip in Response Header

前端 未结 3 996
陌清茗
陌清茗 2020-12-30 08:39

In Firebug the request header has the following entry:
Accept-Encoding: gzip, deflate

But there\'s no:
Content-Encoding: gzip

相关标签:
3条回答
  • 2020-12-30 09:20

    I am using IIS10 and my web.config has

    <system.webServer>
        <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
        <!-- other config removed for brevity -->
    </system.webServer>
    

    When I do test requests from a browser (Firefox, IE11, Edge, Google Chrome) to a simple MVC application.

    The requests all have Accept-Encoding: gzip, deflate and the responses return Content-Encoding:gzip.

    I Even tested it with Fiddler. Composing the request manually

    GET http://localhost/MyWebApplication HTTP/1.1
    User-Agent: Fiddler
    Host: localhost
    Accept-Encoding: gzip, deflate
    

    and get the same result

    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Type: text/html; charset=utf-8
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Server: Microsoft-IIS/10.0
    X-AspNetMvc-Version: 5.2
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Mon, 18 Jul 2016 15:26:06 GMT
    Content-Length: 3826
    
    ...
    

    Css, Js and all other text based files are being compressed.

    You may need to re-check your configuration to make sure you have the compression properly configured in IIS and your web.config.

    UPDATE:

    I did notice that images were not being compressed

    Request

    GET http://localhost/MyWebApplication/Images/Logo_small.png HTTP/1.1
    User-Agent: Fiddler
    Host: localhost
    Accept-Encoding: gzip, deflate
    

    Response

    HTTP/1.1 200 OK
    Cache-Control: max-age=604800
    Content-Type: image/png
    Last-Modified: Fri, 27 Nov 2015 03:15:22 GMT
    Accept-Ranges: bytes
    ETag: "c9d1fdd9c128d11:0"
    Server: Microsoft-IIS/10.0
    X-Powered-By: ASP.NET
    Date: Mon, 18 Jul 2016 15:33:02 GMT
    Content-Length: 2970
    
    ...
    

    And after some google-fu found out that the images are usually already compressed so gzip was not applied.

    FULL system.webServer from web.config

      <system.webServer>
        <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
       <validation validateIntegratedModeConfiguration="false" />
        <httpErrors errorMode="Custom" existingResponse="Replace">
          <clear />
          <error statusCode="404" responseMode="ExecuteURL" path="/NotFound" />
        </httpErrors>
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <staticContent>
          <remove fileExtension=".woff" />
          <remove fileExtension=".woff2" />
          <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
          <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
        </staticContent>
      </system.webServer>
    
    0 讨论(0)
  • 2020-12-30 09:21

    I have similar situation with IIS and gzip configuration

    In Firebug the request header has the following entry: Accept-Encoding: gzip, deflate

    But there's no: Content-Encoding: gzip In the Response Header.

    In my case problem was with antivirus protection. Actually gzipping was applied but antivirus with enabled settings protect http connections (depends on concrete program), unzip response check it and after that rewrite response headers on the fly.

    NOTE: A key attribute when some proxy/antivirus changed your response headers, it is when disappear Content-Length and Transfer-Encoding is added with value chunked.

    0 讨论(0)
  • 2020-12-30 09:37

    I have just had the same problem. The cause ended up being the dynamicCompressionBeforeCache="true" setting. Changing this attribute to "false" fixed the problem.

    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
    

    I run a few sites on a shared server provided by SmarterASP.Net. I raised a support ticket with them and along the way I determined dynamicCompressionBeforeCache="true" to be the culprit.

    I pointed them to the Microsoft documentation covering this attribute, at https://docs.microsoft.com/en-us/iis/configuration/system.webserver/urlcompression, and asked them why a setting of "true" would be causing this issue.

    SmarterASP.Net support referred to a section of the documentation stating...

    If the dynamicCompressionBeforeCache attribute is true when the output cache response has been flushed, dynamic compression will not be performed before the response is put into the output cache.

    ...and they said...

    "We do not save output cache in our server end. So the output cache responses always got flushed and caused the issue."

    I can't say that I fully understand the mechanics here, or why SmarterASP.Net don't save the output cache. But a setting of dynamicCompressionBeforeCache="false" definitely solved the problem for me.

    0 讨论(0)
提交回复
热议问题