none
Enable dynamic http compression in a startup task issue

    Question

  • Hi All,

    We're using a startup task to enable dynamic http compression in applicationHost.config to enable gzip compression for our wfc data service as follows:

    In ServiceDefinition.csdef:

      <Startup>
       <Task commandLine="ConfigureIIS.cmd" executionContext="elevated" taskType="simple" />
      </Startup>
    

    In ConfigureIIS.cmd:

    %windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/json',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom+xml;charset=iso-8859-1',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/xml;charset=iso-8859-1',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/xml;charset=utf-8',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/json;charset=iso-8859-1',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/json;charset=utf-8',enabled='true'] /commit:apphost
    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom+xml;charset=utf-8',enabled='true'] /commit:apphost
    

    The problem is that "atom+xml" is replaced by "atom xml". I.e. the "+" sign is replaced by a white space causing all atom feed being sent over the line uncompressed.

    Any suggestions for a workaround would be much appreciated!!

    BR, Max

    Tuesday, February 08, 2011 11:56 AM

Answers

  • Got it, it didn't matter what the OS was. 

    The difference is that I was typing the command directly into cmd, whereas Azure and is running as a batch or command file. This leads to the parsing of input slightly differently - %1 is the first parameter to the batch file, %2 is the second. 

    What my script was doing with %2b, was saying "second parameter"b. The second parameter was empty, and so it was just atombxml.

    The solution turns out to be simple - we just escape the percentage sign:

    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom%%2bxml;charset=utf-8',enabled='true'] /commit:apphost

    This gets parsed to "percentage sign"2b or %2b, and then gets executed and it becomes a +.

    PHEW! What a slog.

    Andy


    http://blog.bareweb.eu
    • Marked as answer by MaxErixon Thursday, February 10, 2011 2:49 PM
    Wednesday, February 09, 2011 2:06 PM

All replies

  • Hi Max,

    You need to "urlencode" the + in the command to appcmd. 

    I ran your line:

     

    C:\Windows\System32\inetsrv>appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom+xml;charset=utf-8',enabled='true'] /commit:apphost
    Applied configuration changes to section "system.webServer/httpCompression" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

    The result is given as:

     

    C:\Windows\System32\inetsrv>appcmd.exe list config /section:httpcompression
    <system.webServer>
      <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <staticTypes>
          <add mimeType="text/*" enabled="true" />
          <add mimeType="message/*" enabled="true" />
          <add mimeType="application/x-javascript" enabled="true" />
          <add mimeType="application/atom+xml" enabled="true" />
          <add mimeType="application/xaml+xml" enabled="true" />
          <add mimeType="*/*" enabled="false" />
        </staticTypes>
        <dynamicTypes>
          <add mimeType="application/atom xml;charset=utf-8" enabled="true" />
        </dynamicTypes>
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
      </httpCompression>
    </system.webServer>
     

     

    As you said, this has a space rather than the +.

    The command you need is with an encoded +, %2b:

     

    C:\Windows\System32\inetsrv>appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom%2bxml;charset=utf-8',enabled='true'] /commit:apphost
    Applied configuration changes to section "system.webServer/httpCompression" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

    The result is:

    C:\Windows\System32\inetsrv>appcmd.exe list config /section:httpcompression
    <system.webServer>
      <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compresse
    d Files">
        <staticTypes>
          <add mimeType="text/*" enabled="true" />
          <add mimeType="message/*" enabled="true" />
          <add mimeType="application/x-javascript" enabled="true" />
          <add mimeType="application/atom+xml" enabled="true" />
          <add mimeType="application/xaml+xml" enabled="true" />
          <add mimeType="*/*" enabled="false" />
        </staticTypes>
        <dynamicTypes>
          <add mimeType="application/atom xml;charset=utf-8" enabled="true" />
          <add mimeType="application/atom+xml;charset=utf-8" enabled="true" />
        </dynamicTypes>
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
      </httpCompression>
    </system.webServer>

    Thanks

    Andy

     

     


    http://blog.bareweb.eu
    Tuesday, February 08, 2011 12:29 PM
  • Hi Andy,

     

    I just tried the following:

    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom%2bxml;charset=iso-8859-1',enabled='true'] /commit:apphost
    

    And the result was:

    <add mimeType="application/atombxml;charset=iso-8859-1" enabled="true" />
    

    after the startup task was completed. I.e "%2b" was replaced by "b", not "+" as expected.

    Br, Max 

    • Edited by MaxErixon Tuesday, February 08, 2011 2:09 PM
    Tuesday, February 08, 2011 1:50 PM
  • Hum, not sure what's going on here. Did you do this locally, or in the cloud? What OS?

    Mine was locally (Win7), the exact command was:

    C:\Windows\System32\inetsrv>appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom%2bxml;charset=utf-8',enabled='true'] /commit:apphost

    Applied configuration changes to section "system.webServer/httpCompression" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

     

    When I typed your command in again, I get a duplicate key error - suggesting it's still working for me:

    C:\>%windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynam

    icTypes.[mimeType='application/atom%2bxml;charset=utf-8',enabled='true'] /commit

    :apphost

    ERROR ( message:New add object missing required attributes. Cannot add duplicate

     collection entry of type 'add' with unique key attribute 'mimeType' set to 'app

    lication/atom+xml;charset=utf-8'

    . )


    http://blog.bareweb.eu
    Tuesday, February 08, 2011 1:57 PM
  • There's also something weird going on with your example charset, which is iso-8859-1 which is Latin-1 not utf8. Sure that's the right output?

    Try listing it at the command line using appcmd.exe list config /section:httpcompression


    http://blog.bareweb.eu
    Tuesday, February 08, 2011 1:59 PM
  • I deployed to the cloud, Azure 1.3, through the publish feature in visual studio 2010.

    Sorry about the mixed input and output. I'm adding for both iso-8859-1 and utf8 and was a bit sloppy when i copied the result. But the issue is the same, i.e. "%2b" is replaced by "b", not "+" as expected.

     

    ....I've changed my previous post to reflect the actual input and output. 

    BR, Max.

    Tuesday, February 08, 2011 2:06 PM
  • hmm again I get a reasonable result locally:

    <dynamicTypes>

      <add mimeType="application/atom+xml;charset=iso-8859-1" enabled="true" />

    </dynamicTypes>

     

    Can you tell me what OS Family you're using? Check your Service Conf file. 

    Andy


    http://blog.bareweb.eu
    Tuesday, February 08, 2011 7:41 PM
  • Hi Andy,

     

     

     

    osFamily="1" osVersion="*"

    Thanks for your support!

     

    Br, Max.

    Wednesday, February 09, 2011 7:38 AM
  • Got it, it didn't matter what the OS was. 

    The difference is that I was typing the command directly into cmd, whereas Azure and is running as a batch or command file. This leads to the parsing of input slightly differently - %1 is the first parameter to the batch file, %2 is the second. 

    What my script was doing with %2b, was saying "second parameter"b. The second parameter was empty, and so it was just atombxml.

    The solution turns out to be simple - we just escape the percentage sign:

    %windir%\system32\inetsrv\appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/atom%%2bxml;charset=utf-8',enabled='true'] /commit:apphost

    This gets parsed to "percentage sign"2b or %2b, and then gets executed and it becomes a +.

    PHEW! What a slog.

    Andy


    http://blog.bareweb.eu
    • Marked as answer by MaxErixon Thursday, February 10, 2011 2:49 PM
    Wednesday, February 09, 2011 2:06 PM
  • Hi Andy,

     

    This looks promising. I'll deploy to Azure in a couple of hours and Iäll get back with the results! Again, thanks for your support!

    Br, Max.

    Thursday, February 10, 2011 8:59 AM
  • Hi Andy,

    I can confirm that your solution worked! I.e. "%%2b" does it!! Thank you very much!

    BR, Max.

    Thursday, February 10, 2011 2:49 PM
  • I've done all the above, and with RDP I can connect to my webrole instance in Azure and look at applicationHost.config to prove to myself all is as it should be.  However, compression still does not occur which I see in Fiddler.  After many days reading postings the conclusion I see most often is "compression used to work in v1.2, but stopped working in v1.3 of the Azure SDK".  That is my feeling now too, since everything looks completely right but compression still does not occur (this is data coming back from WCF DataServices).

    It would be nice to see some definitive statement about this from Microsoft. Meanwhile I've given up.

    Tuesday, April 05, 2011 10:37 PM
  • Hi,

    We're using SDK version 1.4.20227.1419 and gzip compression is working fine. Are you sure that the client is sending the appropriate accept-encoding headers?

     

    Br, Max.

    Wednesday, April 06, 2011 7:27 AM