[英]node, express app returns text/javascript response header (Content-Type) in spite of setting application/javascript
I am trying to return jsonp from my express, nodejs application and I keep getting text/javascript instead of application/javascript (which I think should be the correct Content-Type). 我试图从我的express,nodejs应用程序返回jsonp,并且不断获取文本/ javascript而不是application / javascript(我认为这应该是正确的Content-Type)。 I am not bothered about IE < 8. The various ways that I have tried to set the content-type when returning the result is shown below:
我不担心IE <8。返回结果时尝试设置内容类型的各种方法如下所示:
// Method 1
res.setHeader('Content-Type', 'application/javascript');
res.status(200).jsonp(result);
// Method 2
res.format({
'application/javascript': function() {
res.status(200).jsonp(result);
}
});
// Method 3
res.set('Content-Type', 'application/javascript');
res.status(200).jsonp(result);
But no matter what, the Content-Type that I get is always text/javascript as shown below. 但是无论如何,我得到的Content-Type始终是text / javascript,如下所示。 I also get 'nosniff' header twice in the response headers :-/ I have it only once in my nginx.conf file which I have thoroughly checked.
我在响应标头中也得到了两次“ nosniff”标头:-/在我彻底检查过的nginx.conf文件中,只有一次。 Even did a nginx -t and it says config is fine.
甚至做了nginx -t并说config很好。
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 12 May 2016 05:06:28 GMT
Content-Type: text/javascript; charset=utf-8
Content-Length: 433
Connection: keep-alive
Keep-Alive: timeout=5
X-Powered-By: Express
Vary: Accept
X-Content-Type-Options: nosniff
ETag: W/"1b1-1ZnUnapTaayP/+6QW4iqXQ"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Strict-Transport-Security: max-age=315360000; includeSubdomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
I am using nginx as a reverse proxy using the 'upstream thingy'. 我正在使用“上游thingy”将nginx用作反向代理。 I am also using bodyParser in my application.
我也在我的应用程序中使用bodyParser。 Please let me know if any further information is needed as I am absolutely new to node/express.
请让我知道是否需要任何进一步的信息,因为我绝对不熟悉node / express。 Thanks
谢谢
I'm afraid that the content type is hard coded in Express. 恐怕内容类型在Express中是硬编码的。 See here .
看这里 。
By the looks of it, the only way around that is to re-implement .jsonp()
yourself (or create an issue on GitHub for the Express devs to fix it). 从外观
.jsonp()
,唯一的解决方法是自己重新实现.jsonp()
(或在GitHub上为Express开发人员创建问题以修复它)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.