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

Make client.ip available before socket connection is established #3287

Closed
falkoschindler opened this issue Jun 26, 2024 · 0 comments · Fixed by #3445
Closed

Make client.ip available before socket connection is established #3287

falkoschindler opened this issue Jun 26, 2024 · 0 comments · Fixed by #3445
Labels
enhancement New feature or request
Milestone

Comments

@falkoschindler
Copy link
Contributor

Description

This change has already been part of PR #2399, which was scheduled for version 2.0.0. But because we could use part of this PR without any breaking changes earlier (PR #3286), we extracted the new client.ip implementation into this issue.

The new implementation might look like this:

client.py

@property
def ip(self) -> Optional[str]:
    """Return the IP address of the client, or None if it is an
    `auto-index page <https://nicegui.io/documentation/section_pages_routing#auto-index_page>`_."""
    return self.request.client.host if self.request is not None and self.request.client is not None else None

test_page.py

def test_ip(screen: Screen):
    @ui.page('/')
    def page():
        ui.label(ui.context.client.ip or 'unknown')

    screen.open('/')
    screen.should_contain('127.0.0.1')
@falkoschindler falkoschindler added the enhancement New feature or request label Jun 26, 2024
@falkoschindler falkoschindler added this to the 2.0.0 milestone Jun 26, 2024
@falkoschindler falkoschindler linked a pull request Aug 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant