diff --git a/README.md b/README.md index 07d9778..6d9de4e 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,11 @@ async def main(): params_list=[ RequestParams( method='GET', - path='https://ya.ru', + url='https://ya.ru', ), RequestParams( method='GET', - path='https://ya.ru', + url='https://ya.ru', headers={'some_header': 'some_value'}, ), ] @@ -193,7 +193,7 @@ for more info see [aiohttp doc](https://docs.aiohttp.org/en/stable/client_advanc @dataclass class RequestParams: method: str - path: _RAW_URL_TYPE + url: _RAW_URL_TYPE trace_request_ctx: Optional[Dict[str, Any]] = None kwargs: Optional[Dict[str, Any]] = None ``` @@ -209,7 +209,7 @@ def requests( You can find an example of usage above or in tests. But basically `RequestParams` is a structure to define params for `ClientSession.request` func. -`method`, `path`, `headers` `trace_request_ctx` defined outside kwargs, because they are popular. +`method`, `url`, `headers` `trace_request_ctx` defined outside kwargs, because they are popular. There is also an old way to change URL between retries by specifying ```url``` as list of urls. Example: ```python diff --git a/aiohttp_retry/client.py b/aiohttp_retry/client.py index 9d97af7..16f7dce 100644 --- a/aiohttp_retry/client.py +++ b/aiohttp_retry/client.py @@ -55,7 +55,7 @@ def exception(self, msg: str, *args: Any, **kwargs: Any) -> None: pass @dataclass class RequestParams: method: str - path: _RAW_URL_TYPE + url: _RAW_URL_TYPE headers: Optional[Dict[str, Any]] = None trace_request_ctx: Optional[Dict[str, Any]] = None kwargs: Optional[Dict[str, Any]] = None @@ -98,8 +98,8 @@ async def _do_request(self) -> ClientResponse: params = self._params_list[-1] response: ClientResponse = await self._request_func( - method=params.method, - path=params.path, + params.method, + params.url, headers=params.headers, trace_request_ctx={ 'current_attempt': current_attempt, @@ -351,10 +351,11 @@ def _make_request( url_list = _url_to_urls(url) params_list = [RequestParams( method=method, - path=path, + url=url, + headers=kwargs.pop('headers', {}), trace_request_ctx=kwargs.pop('trace_request_ctx', None), kwargs=kwargs, - ) for path in url_list] + ) for url in url_list] return self._make_requests( params_list=params_list, diff --git a/setup.py b/setup.py index e8be2ce..7f55ee2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='aiohttp_retry', - version='2.8.1', + version='2.8.2', description='Simple retry client for aiohttp', long_description=long_description, long_description_content_type="text/markdown", diff --git a/tests/test_client.py b/tests/test_client.py index be3b0ed..a1d8b07 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -368,17 +368,17 @@ async def evaluate_response(response: ClientResponse) -> bool: assert test_app.counter == 3 -async def test_multiply_paths_by_requests(aiohttp_client): +async def test_multiply_urls_by_requests(aiohttp_client): retry_client, test_app = await get_retry_client_and_test_app_for_test(aiohttp_client) async with retry_client.requests( params_list=[ RequestParams( method='GET', - path='/internal_error', + url='/internal_error', ), RequestParams( method='GET', - path='/ping', + url='/ping', ), ] ) as response: @@ -398,11 +398,11 @@ async def test_multiply_methods_by_requests(aiohttp_client): params_list=[ RequestParams( method='POST', - path='/ping', + url='/ping', ), RequestParams( method='GET', - path='/ping', + url='/ping', ), ] ) as response: @@ -420,11 +420,11 @@ async def test_change_headers(aiohttp_client): params_list=[ RequestParams( method='GET', - path='/check_headers', + url='/check_headers', ), RequestParams( method='GET', - path='/check_headers', + url='/check_headers', headers={'correct_headers': 'True'}, ), ] @@ -448,3 +448,15 @@ async def test_additional_params(aiohttp_client): assert text == 'Ok!' await retry_client.close() + + +async def test_request_headers(aiohttp_client): + retry_client, test_app = await get_retry_client_and_test_app_for_test(aiohttp_client) + async with retry_client.get(url='/check_headers', headers={'correct_headers': 'True'}) as response: + text = await response.text() + assert response.status == 200 + assert text == 'Ok!' + + assert test_app.counter == 1 + + await retry_client.close()