Skip to content

Protocol not set when using SSL in native mode #4814

@nachobacanful

Description

@nachobacanful

First Check

  • I added a very descriptive title here.
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

from nicegui import ui

ui.run(
    port=8443,
    native=True
    ssl_certfile="<path_to_certfile>",
    ssl_keyfile="<path_to_keyfile>",
)

Description

When using ssl_certfile and ssl_keyfile in conjunction with native=True NiceGUI passes in the wrong protocol (http) to the native PyWebView window. This launches the browser window, but it launches with the http protocol, and because it's a native window, there is no way to manually correct this, resulting in a broken application that doesn't load (protocol error). The expected behavior is that the protocol URL is updated to https when passing in SSL values, directing the browser window to the correct protocol URL. The source of the issue is not that SSL is not used, but rather that the URL is not updated to reflect HTTPS.

The correct protocol is defined here:

nicegui/nicegui/ui_run.py

Lines 187 to 190 in 26765aa

if kwargs.get('ssl_certfile') and kwargs.get('ssl_keyfile'):
protocol = 'https'
else:
protocol = 'http'

Yet it is not used here:

native_module.activate(native_host, port, title, width, height, fullscreen, frameless)

and here
'url': f'http://{host}:{port}',

Solution:

  1. The definition should be moved up a couple of lines before its (and passed in) use here:

    native_module.activate(native_host, port, title, width, height, fullscreen, frameless)

  2. The function definition should be updated to take a protocol

    def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:

    and here
    def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:

    and here
    host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool,

    and lastly it should be chanched from "http://... to "{protocol}://... here
    'url': f'http://{host}:{port}',

It is correctly used here:
urls = [(f'{protocol}://{ip}:{port}' if port != '80' else f'{protocol}://{ip}') for ip in sorted_ips]

note

Fixing this issue would require to update two function signature definitions to pass in protocol:

host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool,

def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:

NiceGUI Version

2.11.1

Python Version

3.12.3

Browser

Other

Operating System

Windows

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugType/scope: Incorrect behavior in existing functionalityreviewStatus: PR is open and needs review🟡 mediumPriority: Relevant, but not essential

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions