How to add Encoding for specific file types? [Answered]RSS

6 replies

Last post Feb 04, 2011 07:26 AM by JohnBlackIIS

  • How to add Encoding for specific file types?

    Feb 02, 2011 02:19 AM|JohnBlackIIS|LINK

    Hi folks! I have .SVG & .SVGZ files. I set up MIME-types for them (image/svg+xml). It's okay. However it's not enough for .SVGZ files (gzipped SVG files) - browsers don't decode it before reading. With Apache it's can easily be done with one line at .htaccess file: "AddEncoding gzip svgz" - as a result it adds HTTP-header "Content-Encoding: gzip". And after that browsers firstly decode SVGZ files and than read it as plain XML. With IIS7 I can't achieve same thing - server doesn't says to browsers to decode it first. Question: how to configure IIS7 to add encoding "gzip" for SVGZ files (to add HTTP-header "Content-Encoding: gzip")? Preferably with .config files. And how to do the same with IIS6? Thank you in advanced! :) p.s. Sorry for my English, it's not native language...
  • Re: How to add Encoding for specific file types?

    Feb 03, 2011 04:23 AM|Lloydz|LINK

    Hi,

    As far as I know, you cannot specify the "Content-Encoding" HTTP-Header in MIME-type settings. However, you can create an HTTP-Module to add the header for sgvz request. If it is IIS6, you will need to create an ISAPI filter to implement this.

    Thanks.

  • Re: How to add Encoding for specific file types?

    Feb 03, 2011 06:14 AM|onder7973|LINK

    For IIS7, it is possible with urlRewrite 2.0. You need to specify outbound rules to append the header correctly. Thus in the web.config of your site, you would have something like this:

     

    <system.webServer>
        <rewrite>
            <outboundRules>
                <rule name="Rewrite SVGZ header" preCondition="IsSVGZ" stopProcessing="true">
                    <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
                    <action type="Rewrite" value="gzip" />
                </rule>
                <preConditions>
                    <preCondition name="IsSVGZ">
                        <add input="{PATH_INFO}" pattern="\.svgz$" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
        <staticContent>
            <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
            <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
        </staticContent>
    </system.webServer>
  • Re: How to add Encoding for specific file types?

    Feb 03, 2011 06:53 AM|KristoferG|LINK

    Lloydz,

    I am curious, why use a module and not a handler? Wouldn't it be more efficient to run the custom code only for the sgvz extension, instead of all requests?

    Kristofer Gafvert

    http://www.it-notebook.org
  • Re: How to add Encoding for specific file types?

    Feb 03, 2011 11:00 PM|Lloydz|LINK

    Hi Kristofer,

    Thank you for replying.
    Since OP has already added the MIME-type for the sgvz extension, IIS knows how to serve the sgvz files(although not completely correct). So I think what OP need and want to do is only to set the Content-Encoding HTTP header for the request rather than how to process it. That's why I mentioned module and not handler. Of course, I agree with running custom code for only sgvz extension could be a better solution. It depends on OP's choice.

    Thanks.

  • Re: How to add Encoding for specific file types?

    Feb 04, 2011 12:08 AM|KristoferG|LINK

    Thanks Lloydz, I get the idea now of how you think.

    Kristofer Gafvert

    http://www.it-notebook.org
  • Re: How to add Encoding for specific file types?

    Feb 04, 2011 07:26 AM|JohnBlackIIS|LINK

    Thank you so much for your reply!!! I hope it'll help me (I'll give a try a bit later)/ Thanks again! :)