Fixing MJPEG streaming in Werkzeug by taking advantage of `direct_passthrough` (#2277)

pull/2281/head
St. John Johnson 2016-06-11 20:50:10 -07:00 committed by Paulus Schoutsen
parent f5fc4cd97f
commit b2b1804f5e
2 changed files with 11 additions and 9 deletions

View File

@ -89,8 +89,6 @@ class Camera(Entity):
def mjpeg_stream(self, response): def mjpeg_stream(self, response):
"""Generate an HTTP MJPEG stream from camera images.""" """Generate an HTTP MJPEG stream from camera images."""
import eventlet import eventlet
response.content_type = ('multipart/x-mixed-replace; '
'boundary=--jpegboundary')
def stream(): def stream():
"""Stream images as mjpeg stream.""" """Stream images as mjpeg stream."""
@ -112,9 +110,11 @@ class Camera(Entity):
except GeneratorExit: except GeneratorExit:
pass pass
response.response = stream() return response(
stream(),
return response content_type=('multipart/x-mixed-replace; '
'boundary=--jpegboundary')
)
@property @property
def state(self): def state(self):
@ -196,4 +196,4 @@ class CameraMjpegStream(CameraView):
def handle(self, camera): def handle(self, camera):
"""Serve camera image.""" """Serve camera image."""
return camera.mjpeg_stream(self.Response()) return camera.mjpeg_stream(self.Response)

View File

@ -70,9 +70,11 @@ class MjpegCamera(Camera):
def mjpeg_stream(self, response): def mjpeg_stream(self, response):
"""Generate an HTTP MJPEG stream from the camera.""" """Generate an HTTP MJPEG stream from the camera."""
stream = self.camera_stream() stream = self.camera_stream()
response.mimetype = stream.headers[CONTENT_TYPE_HEADER] return response(
response.response = stream.iter_content(chunk_size=1024) stream.iter_content(chunk_size=1024),
return response mimetype=stream.headers[CONTENT_TYPE_HEADER],
direct_passthrough=True
)
@property @property
def name(self): def name(self):