diff --git a/ferenda/devel.py b/ferenda/devel.py index e5788d78..a906eed8 100644 --- a/ferenda/devel.py +++ b/ferenda/devel.py @@ -155,13 +155,23 @@ def handle_streaming_test(self, environ): 'src': request_uri(environ) + "?stream=true"})])]) def handle_streaming_test_stream(self, environ, start_response): + # using this instead of text/plain prevent chrome from + # buffering at the beginning (according to + # https://stackoverflow.com/q/20508788, there are three ways + # of overcoming this: The "X-Content-Type-Options: nosniff" + # header, sending at least 1024 bytes of data right away, or + # using a non text/plain content-type. The latter seems the + # easiest. + content_type = 'application/octet-stream' # the second header disables nginx/uwsgi buffering so that # results are actually streamed to the client, see # http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html#uwsgi_buffering - writer = start_response('200 OK', [('Content-Type', 'text/plain'), + writer = start_response('200 OK', [('Content-Type', content_type), ('X-Accel-Buffering', 'no')]) rootlogger = self._setup_streaming_logger(writer) log = logging.getLogger(__name__) + # log.info("1024 bytes of start data: " + "x" * 1024) + # sleep(1) log.debug("Debug messages should work") sleep(1) log.info("Info messages should work") @@ -224,7 +234,7 @@ def handle_change_parse_options(self, environ, params): ]) def handle_change_parse_options_stream(self, environ, start_response): - writer = start_response('200 OK', [('Content-Type', 'text/plain'), + writer = start_response('200 OK', [('Content-Type', 'application/octet-stream'), ('X-Accel-Buffering', 'no')]) rootlogger = self._setup_streaming_logger(writer) # now do the work diff --git a/ferenda/res/js/ferenda.js b/ferenda/res/js/ferenda.js index 499e034b..edc83508 100644 --- a/ferenda/res/js/ferenda.js +++ b/ferenda/res/js/ferenda.js @@ -123,7 +123,7 @@ $(document).ready(function () { window.location.href=suggestion.url }); - /* Functionality to show streaming logs for long-running commands (currently not working in Chrome) */ + /* Functionality to show streaming logs for long-running commands */ output = $('#streaming-log-output'); if (output) { // console.log("Setting up ajax call to stream log output") @@ -132,26 +132,15 @@ $(document).ready(function () { dataType: 'text', url: output.attr('src'), xhrFields: { - // Chrome refuses to call this during the actual response time, it's only called when response is finished (works as expected in Safari/Firefox) onprogress: function(e) { // console.log('onprogress: response len is ' + e.currentTarget.response.length); output.text(e.currentTarget.response); } } }); - /* - i = setInterval(function() { - if (connection.readyState > 2) { - console.log('poll: response len is ' + connection.responseText.length); - } else { - console.log('poll: readystate still in ' + connection.readyState); - } - }, 200); - */ connection.done(function(data) { // console.log('Complete response = ' + data); output.text(data); - // clearInterval(i); }); }