Here is my flask code in a file called main.py -- I am trying to get a simple server-sent-event stream going:
import time
from flask import Flask, Response
from werkzeug.serving import WSGIRequestHandler
app = Flask(__name__)
def counter():
i = 0
while True:
i = i+1
yield "data: " + str(i) + "\n\n"
time.sleep(1)
@app.route('/stream')
def send_message():
return Response(
counter(),
mimetype='text/event-stream',
headers={
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=55'
}
)
if __name__ == "__main__":
WSGIRequestHandler.protocol_version = "HTTP/1.1"
app.run(port=5001)
When I run this app with python main.py and open it up in a browser, the response headers read BOTH Connection: keep-alive AND Connection: close.
Why is this happening? How can I get flask to only use the keep-alive header?
