Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

r0fls
Copy link
Contributor

@r0fls r0fls commented Oct 17, 2017

Fixes: #977

## 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".
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea

@r0fls
Copy link
Contributor Author

r0fls commented Oct 17, 2017

@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.

@messense
Copy link
Contributor

Can we make request.endpoint a lazy property on request class? Ideally it should only be constructed when accessing it.

@@ -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):
Copy link

@profuel profuel Nov 11, 2017

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)

@ahopkins
Copy link
Member

@r0fls Are we keeping this? Can you either update to resolve conflicts or close it?

@ahopkins
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants