From e2509da1baba9571f621d21c543487dc48079cd4 Mon Sep 17 00:00:00 2001 From: Emory P Date: Mon, 9 Dec 2013 02:18:02 -0500 Subject: [PATCH] fix nginx x-accel-redirect/x-sendfile with unicode path names --- api/media.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/api/media.py b/api/media.py index d8a729f..8347ddd 100755 --- a/api/media.py +++ b/api/media.py @@ -40,6 +40,17 @@ def transcode(process): @app.route('/rest/stream.view', methods = [ 'GET', 'POST' ]) def stream_media(): + + @after_this_request + def add_header(response): + if 'X-Sendfile' in response.headers: + xsendfile = response.headers['X-Sendfile'] or '' + redirect = config.get('base', 'accel-redirect') + if redirect and xsendfile: + response.headers['X-Accel-Charset'] = 'utf-8' + response.headers['X-Accel-Redirect'] = redirect + xsendfile.encode('UTF8') + app.logger.debug('X-Accel-Redirect: ' + redirect + xsendfile.encode('UTF8')) + return response status, res = get_entity(request, Track) if not status: @@ -125,10 +136,6 @@ def stream_media(): response.headers['Content-Type'] = dst_mimetype response.headers['Accept-Ranges'] = 'bytes' response.headers['X-Content-Duration'] = str(duration) - redirect = config.get('base', 'accel-redirect') - if(redirect): - response.headers['X-Accel-Redirect'] = redirect + res.path - app.logger.debug('X-Accel-Redirect: ' + response.headers['X-Accel-Redirect']) res.play_count = res.play_count + 1 res.last_play = now()