Skip to content

Commit

Permalink
solved chrome streaming issues
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanm committed Jul 25, 2018
1 parent 61c05c4 commit 0c34e1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 12 additions & 2 deletions ferenda/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions ferenda/res/js/ferenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
});

}
Expand Down

0 comments on commit 0c34e1a

Please sign in to comment.