将标头添加到307重定向

时间:2015-06-05 15:30:56

标签: node.js http redirect http-status-code-307

除了位置之外,你是否可以添加/修改307标题?我试图在Node.js中做到这一点,似乎新添加的标题' X-Atlassian-Token':' no-check'客户不使用。

    res.writeHead(307,
        {
            'Location': 'http://www.mytest.com?os_authType=basic',
            'Content-Type': 'multipart/form-data',
            'X-Atlassian-Token': 'no-check'
        });
    res.end();

有人在Stackoverflow上问了同样的问题,一个人回复了 -

Is it possible to set some http headers while http-redirect(302 or 307)?

"实际上,通过Java对象,您可以设置请求属性,但不能设置标题。我自己正在寻找答案。我认为这是一个故意的限制,以防止伪造身份验证令牌和通过标头发送的其他信息。 如果找到解决方案,我会发布解决方案。"

1 个答案:

答案 0 :(得分:1)

  

除了Location之外,您是否无法添加/修改307标题?

不,这不是真的。运行代码会显示响应,包括指定的状态代码和额外的标题:

HTTP/1.1 307 Temporary Redirect
Location: http://www.mytest.com?os_authType=basic
Content-Type: multipart/form-data
X-Atlassian-Token: no-check
Date: Sat, 06 Jun 2015 13:40:41 GMT
Connection: keep-alive
Transfer-Encoding: chunked

如果没有达到预期的效果,请参阅this other answer to the same question

  

您还应确保响应标头引用该响应,而不是客户端重定向到的资源。

也就是说,X-Atlassian-Token: no-check标题赢得会被转移到后续请求中(具体而言,不会被客户端发送)

相关问题