最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get raw HTTP header string in Node.js with express.js - Stack Overflow

programmeradmin7浏览0评论

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 accepted).

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.

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).

Now is there a way how I can access those raw strings in my express app?

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 accepted).

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.

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).

Now is there a way how I can access those raw strings in my express app?

Share Improve this question edited Jan 11, 2021 at 14:50 Dharman 33.3k27 gold badges101 silver badges146 bronze badges asked May 13, 2013 at 8:42 cschaefflercschaeffler 4533 gold badges6 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

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);
const express = require('express')

const app = express()

app.listen(3000)

app.use((req, res, next) => {
  const headersJson = JSON.stringify(req.headers)
  console.log(headersJson)

  // Save into file using fs module

  // save into database

  next()
})

发布评论

评论列表(0)

  1. 暂无评论