remove charset from Content-type in express response

Viewed 1504

Im working on the following api call using express library:

router.get('/WebServers', (req, res) => {
  log.debug('api v2 - List WebServers');
  const servers = webServersModel.transformWebServers();
  res.set('Content-Type', 'application/json');
  res.json({WebServers: servers});
});

My client for some unkown reason accepts only http headers with content type:"application/json" however express seems to append "; charset=utf-8" to all of my resonses. after digging around Ive found this piece of code in the express/lib/response.js file: enter image description here

Express seems to be hard-coding the appending of the charset to the response. following this code Ive tried adding to the top of my code the following line: express.static.mime.charsets.lookup=function() {}; however that didnt work. any ideas how to solve this?

1 Answers

Replace res.set() with res.writeHead(). Fixed it for me last week :)

Related