-
-
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 handler name to request as endpoint #979
Conversation
## Accessing the handler name with the request.endpoint attribute | ||
|
||
The `request.endpoint` attribute holds the handler's name. For instance, the below | ||
route will return "hello". |
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 in a blueprint, it should also include the blueprint's name? For example: foo.hello
, bar.hello
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 like that idea
@messense if you see a better way of implementing this with the blueprint name, let me know. I'm not fond of the if statement, as it will be executed on each request. |
Can we make |
@@ -247,6 +247,12 @@ def websocket(self, uri, host=None, strict_slashes=None, | |||
def response(handler): | |||
async def websocket_handler(request, *args, **kwargs): | |||
request.app = self | |||
if not getattr(handler, '__blueprintname__', 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.
will you please make this (and used in converted_response_type) portion a function.
Also I would drop 'else' statement there, so it looks like:
def _get_endpoint(handler):
if not getattr(handler, '__blueprintname__', False):
return handler.__name__
return getattr(handler,
'__blueprintname__',
'') + handler.__name__
and used as
request.endpoint = _get_endpoint(handler)
@r0fls Are we keeping this? Can you either update to resolve conflicts or close it? |
I updated this PR to current master, made a few tweaks, added some tests, but was not allowed to push to this branch. Therefore, I am closing and will submit a new PR. |
Fixes: #977