How to make Flask/ keep Ajax HTTP connection alive?

前端 未结 2 455
南方客
南方客 2020-12-09 19:38

I have a jQuery Ajax call, like so:

    $(\"#tags\").keyup(function(event) {
      $.ajax({url: \"/terms\",
        type: \"POST\",
        contentType: \"ap         


        
相关标签:
2条回答
  • 2020-12-09 20:12

    The default request_handler is WSGIRequestHandler.

    Before app.run(), Add one line, WSGIRequestHandler.protocol_version = "HTTP/1.1"

    Don't forget from werkzeug.serving import WSGIRequestHandler.

    0 讨论(0)
  • 2020-12-09 20:24

    Werkzeug's integrated web server builds on BaseHTTPServer from Python's standard library. BaseHTTPServer seems to support Keep-Alives if you set its HTTP protocol version to 1.1.

    Werkzeug doesn't do it but if you're ready to hack into the machinery that Flask uses to instantiate Werkzeug's BaseWSGIServer, you can do it yourself. See Flask.run() which calls werkzeug.serving.run_simple(). What you have to do boils down to BaseWSGIServer.protocol_version = "HTTP/1.1".

    I haven't tested the solution. I suppose you do know that Flask's web server ought to be used for development only.

    0 讨论(0)
提交回复
热议问题