如何在Express框架中设置位置响应HTTP头?

如何在Express中设置响应Location HTTP标头? 我试过这个,但是不起作用:

  Controller.prototype.create = function(prop, res) { var inst = new this.model(prop); inst.save(function(err) { if (err) { res.send(500, err); } res.location = '/customers/' + inst._id; res.send(201, null); }); }; 

这个代码是在MongoDB中保存一个新的文档,并在竞争时设置位置并发送201响应。 得到了这个回应,没有Location标题设置:

 HTTP/1.1 201 Created X-Powered-By: Express Content-Length: 0 Date: Mon, 18 Feb 2013 19:08:41 GMT Connection: keep-alive 

编辑 :作为uʍopǝpısdn (酷尼克btw)答案, res.setHeader作品。 但为什么res.location不?

你正在设置res.locationres.location是一个函数。

 res.location('/customers/' + inst._id) 

res对象公开了setHeader()

 res.setHeader('Location', foo); 

尝试而不是res.location