Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions providers/http/src/airflow/providers/http/hooks/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def _set_base_url(self, connection: Connection) -> None:
self.base_url = host
else:
self.base_url = f"{schema}://{host}" if host else f"{schema}://"
if connection.port:
self.base_url = f"{self.base_url}:{connection.port}"
if connection.port:
self.base_url = f"{self.base_url}:{connection.port}"
parsed = urlparse(self.base_url)
if not parsed.scheme:
raise ValueError(f"Invalid base URL: Missing scheme in {self.base_url}")
Expand Down
10 changes: 10 additions & 0 deletions providers/http/tests/unit/http/hooks/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ def test_https_connection(self, mock_get_connection):
hook.get_conn({})
assert hook.base_url == "https://localhost"

@mock.patch("airflow.providers.http.hooks.http.HttpHook.get_connection")
def test_https_connection_port(self, mock_get_connection):
conn = Connection(
conn_id="http_default", conn_type="http", host="https://localhost", schema="https", port=8080
)
mock_get_connection.return_value = conn
hook = HttpHook()
hook.get_conn({})
assert hook.base_url == "https://localhost:8080"

@mock.patch("airflow.providers.http.hooks.http.HttpHook.get_connection")
def test_host_encoded_http_connection(self, mock_get_connection):
conn = Connection(conn_id="http_default", conn_type="http", host="http://localhost")
Expand Down