javascript 如何使用 express.js 在 node.js 中获取原始 http 标头字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16517942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get raw http header string in node.js with express.js
提问by cschaeffler
I currently work with node.js and express.js. For my current project i need to access the raw strings of the HTTP headers (charset and accpeted).
我目前使用 node.js 和 express.js。对于我当前的项目,我需要访问 HTTP 标头(字符集和已接受)的原始字符串。
There is a function in express.js which returns those charsets and accepted headers, however, these are sorted by quality and therefore not useable for me in this special case i need.
express.js 中有一个函数可以返回这些字符集和接受的标头,但是,这些是按质量排序的,因此在我需要的这种特殊情况下对我来说不可用。
req.accepted // Returns sorted array of accepted header
req.acceptedCharsets // Returns sorted array of accepted lang header
However, I need the raw strings (iso-8859-5;q=.2, unicode-1-1;q=0.8, text/*;q=.5, application/json).
但是,我需要原始字符串(iso-8859-5;q=.2,unicode-1-1;q=0.8,text/*;q=.5,application/json)。
Now is there a way how i can access those raw strings in my express app?
现在有没有办法在我的 Express 应用程序中访问这些原始字符串?
Best regards, Crispin
最好的问候,克里斯平
回答by Lassi Kinnunen
req.headers
请求头文件
as in
如
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res){
console.log(req.headers);
res.header('time', 12345);
res.send('Hello World');
});
app.listen(3000);