-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Request.stream #697
Add Request.stream #697
Conversation
does this replace #696? |
I am sorry. |
tests/test_request_stream.py
Outdated
for i in range(1, 250000): | ||
data += str(i) | ||
request, response = app.test_client.post('/stream', data=data) | ||
text = data.replace('1', 'A') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request handler
replaces '1' with 'A'.
This makes the correct result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing.
I removed replacing '1' with 'A'.
sanic/app.py
Outdated
@@ -27,7 +27,7 @@ | |||
class Sanic: | |||
|
|||
def __init__(self, name=None, router=None, error_handler=None, | |||
load_env=True, request_class=None, | |||
load_env=True, request_class=None, is_request_stream=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to set self.is_request_stream = True
in the app.stream
method, if used. This would avoid having to initialize it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So around line 170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your pointing out is correct.
I think it is better to add self.is_request_stream = True
in app.route()
for blueprint.stream()
.
if stream:
self.is_request_stream = True
There is a bug.
I will fix it and add tests. |
I add |
I am sorry for adding code. |
There is a bug. |
I fixed it and added tests. |
So instead of it's own decorator wouldn't it make sense to make it as just a parameter that you can pass in through the regular method decorators? Example: @app.post('/help/<id>', stream=True)
def stream_handler(request):
pass Not necessarily a show-stopper just asking the question. Great work as always @38elements |
Thank you for reviewing. |
I replaced stream decorator to stream parameter. |
Will merge once I create a milestone for this |
Thank you. |
I added a heading in |
we should also remove this from the todo here: https://github.com/channelcat/sanic/blob/master/README.rst#todo |
Trying to execute the code shared by @38elements .
Is the code merged to master ? |
This adds
Request.stream
andstream decorator
, as below.