Skip to content
Open
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
12 changes: 11 additions & 1 deletion packages/http/httpx/kiota_http/httpx_request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import re
import warnings
from datetime import datetime
from typing import Any, Optional, TypeVar, Union
from urllib import parse
Expand Down Expand Up @@ -87,7 +88,16 @@ def __init__(
if not http_client:
http_client = KiotaClientFactory.create_with_default_middleware()
self._http_client: httpx.AsyncClient = http_client
self._base_url: str = str(http_client.base_url) if http_client.base_url is not None else ""
if base_url:
warnings.warn(
"The base_url argument is deprecated. "
"Set base_url on the http_client or on the request adapter instead.",
DeprecationWarning,
stacklevel=2
)
else:
base_url = str(http_client.base_url) if http_client.base_url is not None else ""
self._base_url: str = base_url
if not observability_options:
observability_options = ObservabilityOptions()
self.observability_options = observability_options
Expand Down
18 changes: 14 additions & 4 deletions packages/http/httpx/tests/test_httpx_request_adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
import warnings
from unittest.mock import AsyncMock, Mock, call, patch
from urllib.parse import unquote

Expand Down Expand Up @@ -626,11 +627,20 @@ async def test_send_primitive_async_302_with_location_header_does_not_throw(
assert "location" in resp.headers
await request_adapter.send_primitive_async(request_info, "float", {})

def test_httpx_request_adapter_ignores_base_url_parameter(auth_provider):
request_adapter = HttpxRequestAdapter(auth_provider, base_url="https://no.com")
assert request_adapter.base_url == ""
def test_httpx_request_adapter_uses_base_url_parameter(auth_provider):
with pytest.warns(DeprecationWarning, match="base_url argument is deprecated"):
request_adapter = HttpxRequestAdapter(auth_provider, base_url="https://no.com")
assert request_adapter.base_url == "https://no.com"

def test_httpx_request_adapter_base_url_parameter_wins_over_http_client(auth_provider):
http_client = httpx.AsyncClient(base_url=BASE_URL)
with pytest.warns(DeprecationWarning, match="base_url argument is deprecated"):
request_adapter = HttpxRequestAdapter(auth_provider, http_client=http_client, base_url="https://no.com")
assert request_adapter.base_url == "https://no.com"

def test_httpx_request_adapter_uses_http_client_base_url(auth_provider):
http_client = httpx.AsyncClient(base_url=BASE_URL)
request_adapter = HttpxRequestAdapter(auth_provider, http_client=http_client, base_url="https://no.com")
with warnings.catch_warnings():
warnings.simplefilter("error")
request_adapter = HttpxRequestAdapter(auth_provider, http_client=http_client)
assert request_adapter.base_url == BASE_URL
Loading