Skip to content

Werkzeug/Flask response binary format support #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openapi_core/contrib/werkzeug/responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""OpenAPI core contrib werkzeug responses module"""
from itertools import tee

from werkzeug.datastructures import Headers
from werkzeug.wrappers import Response

Expand All @@ -11,6 +13,10 @@ def __init__(self, response: Response):

@property
def data(self) -> str:
if not self.response.is_sequence:
resp_iter1, resp_iter2 = tee(self.response.iter_encoded())
self.response.response = resp_iter1
return b"".join(resp_iter2)
return self.response.get_data(as_text=True)

@property
Expand Down