Skip to content

Commit

Permalink
fix: pass header kwargs to get openapi endpoints (#6177)
Browse files Browse the repository at this point in the history
JoanFM authored Jul 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e3ea29f commit 09bd765
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jina/clients/base/http.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._endpoints = []

async def _get_endpoints_from_openapi(self):
async def _get_endpoints_from_openapi(self, **kwargs):
def extract_paths_by_method(spec):
paths_by_method = {}
for path, methods in spec['paths'].items():
@@ -39,10 +39,15 @@ def extract_paths_by_method(spec):

import aiohttp

session_kwargs = {}
if 'headers' in kwargs:
session_kwargs = {'headers': kwargs['headers']}

proto = 'https' if self.args.tls else 'http'
target_url = f'{proto}://{self.args.host}:{self.args.port}/openapi.json'
try:
async with aiohttp.ClientSession() as session:

async with aiohttp.ClientSession(**session_kwargs) as session:
async with session.get(target_url) as response:
content = await response.read()
openapi_response = json.loads(content.decode())
@@ -129,7 +134,7 @@ async def _get_results(
request_iterator = self._get_requests(**kwargs)
on = kwargs.get('on', '/post')
if len(self._endpoints) == 0:
await self._get_endpoints_from_openapi()
await self._get_endpoints_from_openapi(**kwargs)

async with AsyncExitStack() as stack:
cm1 = ProgressBar(

0 comments on commit 09bd765

Please sign in to comment.