使用unicode_literals添加标头似乎与Nginx,uWSGI和一个简单的Flask应用程序失败:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from flask import Flask, make_response
app = Flask('test')
@app.route('/')
def index():
response = make_response()
response.status_code = 401
response.headers = {'WWW-Authenticate': 'Basic realm="test"'} # Fail
# response.headers = {b'WWW-Authenticate': b'Basic realm="test"'} # Succeed
return response
if __name__ == '__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
该应用程序可直接用于调试目的或通过Nginx - > uWSGI - > Flask并且运行良好.
WWW-Authenticate标题是正确的.Transfert-Encoding: chunked并丢弃WWW-Authenticate标头.强制b'...') format to add the header make the app works as expected in both …