Azure函数压缩了POST正文

Bha*_*rat 1 azure node.js azure-functions

我有带有Http触发器的nod​​ejs azure函数。我正在使用POST方法并将正文发送到azure函数。由于主体很大,因此使用gzip对其进行压缩。

我在azure函数中收到请求,内容编码标头为'gzip'。我试图使用nodejs

zlib.gunzip(req.body,...) 
Run Code Online (Sandbox Code Playgroud)

它引发了一个错误

错误:标头检查不正确

Aar*_*hen 5

对于JavaScript函数,不支持流传输,并且Function运行时提供请求正文而不是请求对象。C#函数没有特殊处理,因此您可以尝试使用C#函数。

这是一个C#函数,该函数解压缩gzip请求主体,以供您参考。

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);
} 
Run Code Online (Sandbox Code Playgroud)