简体   繁体   English

节点,尽管设置了application / javascript,express app仍返回text / javascript响应标头(Content-Type)

[英]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.

相关问题 在文本文件中保存响应类型“ Content-Type:text / javascript” - Save response type “Content-Type : text/javascript” in text file 尽管有text / javascript内容类型,但仍未执行rails 3 javascript - rails 3 javascript not executed despite a text/javascript content-type in response JavaScript:在响应对象上设置 Content-Type 标头 - JavaScript: Set Content-Type header on Response Object 在Ajax调用中设置自定义的Content-Type响应标头? - Setting a custom Content-Type response header in Ajax call? JavaScript内容类型 - JavaScript content-type 正则表达式:在内容类型http标头中匹配javascript mime类型 - regex: Matching a javascript mime type in content-type http header 在 fetch API 上使用 Content-Type &quot;application/javascript&quot; 发送 post 请求后没有预期的响应被发送 - Response not expected after sending a post request using Content-Type "application/javascript" on fetch API is sent 依赖Content-Type:text / plain来缓解恶意javascript执行是否安全? - Is it safe to rely on Content-Type: text/plain to mitigate malicious javascript execution in response? 如何使用Javascript从URL获取HTTP标头(内容类型) - How to get HTTP header (Content-Type) from URL with Javascript JavaScript 文件的适当内容类型 header 是什么? - What is an appropriate content-type header for JavaScript files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM