1

Our application uses Service Fabric as its backbone and our microservices are Service Fabric Services. After running some auditing using Lighthouse on the front-end, I saw that the recommendation to enable text based compression was listed and began investigating how I can add gzip to some of my responses.

For our Node server, I simply added the compression middleware and used it.

For other services, I went inside of the Web.config and added the following:

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

<httpCompression>
  <dynamicTypes>
    <clear />
    <add enabled="true"  mimeType="application/json"/>
  </dynamicTypes>
  <staticTypes>
    <clear />
    <add enabled="true"  mimeType="application/json"/>
  </staticTypes>
</httpCompression>

Upon reloading my web app, I did notice that the responses were now coming in compressed, but I do not want to necessarily compress all responses.

When I setup any of my endpoints, I follow the following format:

[HttpGet]
[Route("{customer}/items")]
[Authorize]
public Task<ItemsModel> Get()
{
    return _itemsService.GetAsync();
}

Is there a way to enable compression on a per-endpoint basis instead of per-service?

User 5842
  • 2,849
  • 7
  • 33
  • 51
  • See this:https://stackoverflow.com/questions/2775261/how-to-enable-gzip-http-compression-on-windows-azure-dynamic-content – I_Al-thamary Jan 09 '19 at 17:10
  • The c# code can read the configuration settings and determine which responses are using GZIP. – jdweng Jan 09 '19 at 17:14
  • Does this doc about urlcompression help maybe? https://learn.microsoft.com/en-us/iis/configuration/system.webserver/urlcompression – LoekD Jan 10 '19 at 06:00

1 Answers1

0

Here is the process;

  1. Edit your ServiceDefinition.csdef file to contain this in the WebRole tag:

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

  1. In your web-role, create a text file and save it as “EnableCompression.cmd”

  2. EnableCompression.cmd should contain this:

    %windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost %windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost

This simple process will enable dynamic compression for the json returned by the web-role in Azure.

Source:https://cloudmonix.com/blog/how-to-enable-gzip-http-compression-on-windows-azure-endpoint/

You can see also these:

https://basecamp.kony.com/s/question/0D56A00000RbtbBSAR/how-to-enable-gzip-compression-in-mobile-fabric

https://code.i-harness.com/en/q/2a58dd

How to enable gzip HTTP compression on Windows Azure dynamic content

I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37