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
8 changes: 5 additions & 3 deletions packages/http/httpx/kiota_http/httpx_request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def __init__(
self._serialization_writer_factory = serialization_writer_factory
if not http_client:
http_client = KiotaClientFactory.create_with_default_middleware()
self._http_client = http_client
self._http_client: httpx.AsyncClient = http_client
if not base_url:
base_url = ""
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()
Expand All @@ -101,7 +101,9 @@ def base_url(self) -> str:
Returns:
str: The base url
"""
return self._base_url
return self._base_url or str(
self._http_client.base_url
) if self._http_client.base_url is not None else ""

@base_url.setter
def base_url(self, value: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion packages/http/httpx/kiota_http/kiota_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_with_default_middleware(
instantiating default middleware. Defaults to dict[str, RequestOption]=None.

Returns:
httpx.AsycClient: An instance of the AsyncClient object
httpx.AsyncClient: An instance of the AsyncClient object
"""

kiota_async_client = KiotaClientFactory.get_default_client() if client is None else client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def request_handler(request: httpx.Request):
return httpx.Response(200, )
return httpx.Response(
TOO_MANY_REQUESTS,
headers={RETRY_AFTER: "200"}, # value exceeds max delay of 180 secs
headers={RETRY_AFTER: "200"}, # value exceeds max delay of 180 secs
)

# Retry-after value takes precedence over the RetryHandlerOption value specified here
Expand All @@ -238,30 +238,30 @@ def request_handler(request: httpx.Request):
assert resp.status_code == 429
assert RETRY_ATTEMPT not in resp.request.headers


@pytest.mark.asyncio
async def test_max_retries_respected():
"""Test that a request is not retried more than max_retries configured"""

def request_handler(request: httpx.Request):
if RETRY_ATTEMPT in request.headers:
return httpx.Response(200, )
return httpx.Response(
TOO_MANY_REQUESTS,
)
return httpx.Response(TOO_MANY_REQUESTS, )

# Retry-after value takes precedence over the RetryHandlerOption value specified here
handler = RetryHandler(RetryHandlerOption(10, 3, True))
request = httpx.Request(
'GET',
BASE_URL,
headers={RETRY_ATTEMPT: '5'} # value exceeds max retries configured
headers={RETRY_ATTEMPT: '5'} # value exceeds max retries configured
)
mock_transport = httpx.MockTransport(request_handler)
resp = await handler.send(request, mock_transport)
assert resp.status_code == 200
assert RETRY_ATTEMPT in resp.request.headers
assert resp.request.headers[RETRY_ATTEMPT] == '5'


@pytest.mark.asyncio
async def test_retry_options_apply_per_request():
"""Test that a request options are applied per request"""
Expand Down
6 changes: 6 additions & 0 deletions packages/http/httpx/tests/test_httpx_request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,9 @@ async def test_retries_on_cae_failure(
),
]
request_adapter._authentication_provider.authenticate_request.assert_has_awaits(calls)


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)
assert request_adapter.base_url == BASE_URL