1
votes

I have nodejs azure function with the Http trigger. I am using POST method and sending body to the azure function. Since body is large it is compressed using gzip.

I am getting the request in azure function and the content-encoding header is 'gzip'. I tried to use nodejs

zlib.gunzip(req.body,...) 

and it threw an error

Error: incorrect header check

2

2 Answers

7
votes

For JavaScript functions, streaming is not supported and the Functions runtime provides the request body instead of the request object. There is no special handling for C# functions, so you could try using a C# function instead.

Here is a C# function which decompresses gzip request body for your reference.

using System.Net;
using System.IO.Compression;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    var inputStream = await req.Content.ReadAsStreamAsync();
    string decompressedReqBody = string.Empty;
    using (GZipStream decompressionStream = new GZipStream(inputStream, CompressionMode.Decompress))
    {
        using (StreamReader sr = new StreamReader(decompressionStream))
        {
           decompressedReqBody = sr.ReadToEnd();
           log.Info(decompressedReqBody);
        }
    }
    return req.CreateResponse(HttpStatusCode.OK, decompressedReqBody);
} 
-1
votes

Faced similar issue recently. Mistake we did was to set wrong Content-Type header. Changing Content-Type to application/octet-stream from application/json did the trick.