Azure-functions-host: GZip on Azure Functions V3 Not Working For JSON Response

Created on 12 Apr 2021  路  10Comments  路  Source: Azure/azure-functions-host

Hey everyone,

"I feel like I'm taking crazy pills", but I can't find the answer to my problem... I have a group of Azure Functions V3 that are serving up a REST API. They are on an "Always On" App service plan of B1.

In front of our Azure Functions, we are using Azure API Management. (Although this problem occurs when we make calls directly to the functions)

We have a larger API response that returns about 375k of JSON, and noticed that it wasn't being compressed (GZIP).

image

Documents online seems to say it should just work by default, but mine isn't:

https://stackoverflow.com/questions/49339268/how-can-i-enable-gzip-compression-on-azure-functions-v2

Also other people seemed to have this issue previously: https://github.com/Azure/azure-functions-host/issues/4000

I have been searching online for hours, and I have even searched for ways to disable gzip, so I could find the location of the settings so I could verify it wasn't disabled, but to no avail.

I even thought maybe it's compressed but somehow I'm missing it, so I tested it on webpagetest.org:

image

Related question post: https://docs.microsoft.com/en-us/answers/questions/353996/gzip-on-azure-functions.html

feature

All 10 comments

Hi @unearthly85 , Thank you for reaching out to us, checking internally on this issue

Hi @unearthly85 , Are you using Windows or Linux? If it is Linux, can you check if you are using CORS or EasyAuth (Authentication) features, as that puts in a layer of middleware that may not work well with GZIP compression.

Hey @v-anvari !
We are using linux.
We are not using CORS or any Authentication features (Authentication has no identity providers, and Authentication Classic is off).

Hi @unearthly85 , Thank you for the update, we are checking internally for any known issue

Tagging @ConnorMcMahon, for more insights

Hi @unearthly85, We reproduce that the gzip compression just works on Windows, and doesn't work on Linux. Checking this internally if this is explicitly supported in Linux App services or this support needs to be included. Meanwhile, Please go through the following link to check if the steps work for your project scenario how-do-i-enable-gzip-compression-for-linux-azure-app-services

Hey @v-anvari,
When testing locally, there is a problem I find when manually adding the header for Content-Encoding to my .net azure functions.

I attempted to do what was mentioned in how-do-i-enable-gzip-compression-for-linux-azure-app-services.

So we just need to add Content-Encoding: gzip in Response Headers, then we can solve the issue.

Tested by adding the following line: req.HttpContext.Response.Headers.Add("Content-Encoding", "gzip");
to a single response produces the following error in postman:

image
image

I tested this before posting this issue with no results. Is it possible this is because I'm testing locally? I haven't tried this deployed.

I am looking into
builder.Services.AddResponseCompression();
suggested here: https://stackoverflow.com/questions/61688759/enabling-gzip-compression-on-azure-app-service-for-containers

This doesn't work on localhost, but supposedly this isn't possible as seen in the link below, and it does not create any errors on response like manually adding the Content-Encoding: gzip header.
https://stackoverflow.com/questions/49339268/how-can-i-enable-gzip-compression-on-azure-functions-v2

I will see if this works when deployed.

@v-anvari , It appears that Azure Functions doesn't support middleware the same way that Web API does, so I cannot implement gzip response compressions in code like suggested in my prior comment.

At this point, I do not know any way to work around this issue and I am stuck with linux app services being unable to use gzip compression, so I have deployed a new Function app on windows infrastructure.

Edit:
Worth noting, windows based app service plans for the same performance are almost 4x more expensive.

  • B1 Windows: $54
  • B1 Linux: $14

Yeah, not great :-/

Hi @unearthly85 , Thank you for sharing your findings. We are checking with the right team to confirm the support on this scenario.

Cc @ConnorMcMahon, for confirming the supportability

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JasonBSteele picture JasonBSteele  路  3Comments

ElvenSpellmaker picture ElvenSpellmaker  路  3Comments

ahmelsayed picture ahmelsayed  路  4Comments

mathewc picture mathewc  路  4Comments

justinyoo picture justinyoo  路  3Comments