我的 node .js应用程序的模型与express/examples/mvc应用程序类似.
在控制器操作中,我想用一条定制的HTTP消息显示HTTP 400状态.
HTTP/1.1 400 Bad Request
但我想送
HTTP/1.1 400 Current password does not match
我try 了各种方法,但都没有将http状态消息设置为我的自定义消息.
我当前的解决方案控制器功能如下所示:
exports.check = function( req, res) {
if( req.param( 'val')!=='testme') {
res.writeHead( 400, 'Current password does not match', {'content-type' : 'text/plain'});
res.end( 'Current value does not match');
return;
}
// ...
}
一切正常,但...这似乎不是正确的方法.
有没有更好的方法使用express设置http状态消息?