是否支持多个具有相同名称的HTTP标头?

时间:2018-01-28 20:07:08

标签: node.js azure cookies azure-functions

我正在尝试将ASP.net REST后端迁移到Azure Functions。我可能很天真的方法是创建一个catch-all函数,通过Node的http模块代理HTTP请求,然后用更具体的路由缓慢地用本机Azure Functions替换端点。我正在使用CLI,并创建了一个类似于Node的函数:

var http = require("http")

module.exports = function (context, req) {
    var body = new Buffer([])
    var headers = req.headers
    headers["host"] = "my.proxy.target"
    var proxy = http.request({
        hostname: "my.proxy.target",
        port: 80,
        method: req.method,
        path: req.originalUrl,
        headers: headers
    }, function(outboundRes) {
        console.log("Got response")
        context.res.status(outboundRes.statusCode)
        for(header in outboundRes.headers) {
            console.log("Header", header)
            if(header != "set-cookie")
            context.res.setHeader(header, outboundRes.headers[header])
            else
            console.log(outboundRes.headers[header])
        }
        outboundRes.addListener("data", function(chunk) {
            body = Buffer.concat([body, chunk])
        })
        outboundRes.addListener("end", function() {
            console.log("End", context.res)
            context.res.raw(body)
        })
    })
    proxy.end(req.body)
}

这几乎似乎有效,但我的后端使用多个Set-Cookie标头设置了几个cookie。 Node将这些值作为一个cookie值数组运回来,但似乎Azure Functions不接受数组作为值,或者不允许设置多个具有相同名称的头,就像Set-Cookie似乎允许的那样。

支持吗?我用谷歌搜索并检查了Type的TypeScript来源,但它似乎不是。

如果不支持,我应该使用哪些Azure平台服务将404s从一个应用程序故障转移到另一个应用程序,这样我可以慢慢地用功能替换monolith?如果我可以将它们用作后备,函数代理将起作用,但这似乎不可能。

谢谢!

0 个答案:

没有答案