content type 使我写的api变成了文件下载

情况是这样的 我用tornado render了一个简单的页面, 结果用浏览器打开 却提示让我下载, 下载之后是原本应该显示的 页面内容.

后来发现是content type在作怪.

tornado 默认使用的content typeapplication/json 这个是可以让浏览器解析页面的内容的

但是我在nginx里把这个api的路由 不小心加上了
add_header Content-Type application/x-www-form-urlencoded;

Screenshot from 2018-11-01 16-47-16.png

nginx重写response的header是发生在最后一步, 所以 最后面的 Content-Type application/x-www-form-urlencoded 生效了

所以这个页面 因为是 x-www-form-urlencoded 这个属性, 就会提示让你下载..

你可能感兴趣的:(content type 使我写的api变成了文件下载)