Search code examples
apache.net-cf-3.5

Apache gzip SOAP


I am new to Apache and I am trying to figure out how to enable gzip compression to send data over to clients (.NET Compact Framework devices). I am using Apache 2.2 and so far, I have enabled mod_deflate.so but my content send over netwrok is not gzipped. Any idea? much appreciated

UPDATE I am on Windows using Apache 2.2. In my httpd.conf file, I uncommented this line.

LoadModule deflate_module modules/mod_deflate.so

My module Location is in httpd.conf file like this:

<Location /MyModule>
    SetHandler mod_MyModule-handler
</Location>

And in httpd.conf file, I already had all this, so nothing was changed here except that I have uncommented DeflateCompressionLevel 9:

<Location />
    # Insert filter
    SetOutputFilter DEFLATE

    # compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/x-javascript

    #DeflateCompressionLevel 9  //if I uncomment this, server wont start
    # 1 to 9: 9 is the most compressed

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    #The following statement indicate which document types not to compress. Many type of documents do not compress well.
    #At the end (Appendix 1) of this article some more type you might wish to also exclude from compression
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    # install/enable the Apache module mod_headers
    Header append Vary User-Agent env=!dont-vary

    # install/enable the Apache module LoadModule expires_module modules/mod_expires.so
    # turn on the module for this directory
    ExpiresActive on

    # set defaults
    ExpiresByType text/javascript "modification plus 11 months"
    ExpiresByType application/javascript "modification plus 11 months"
    ExpiresByType text/css "modification plus 11 months"

</Location>

Then I restart Apache, send request to it and receive response but response.ContentEncoding does not show "gzip" in .NETCF client. It looks like I am missing something.


Solution

  • uncomment the deflate module

        LoadModule deflate_module modules/mod_deflate.so
    

    and add this stanza to the virts config like this (be sure to include your soap mime type)

    <IfModule deflate_module>
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
    </IfModule>
    

    bash test

    function check_compression {
      curl -s -k -I -H 'Accept-Encoding: gzip,deflate' $1 |grep "Content-Encoding"
    }
    
    check_compression  http://your.url.com
    

    If that doesn't work, check that you have the mime type set correctly for the soap response.