Skip to content

Commit

Permalink
Split out confusing path combination logic to separate method (#21247)
Browse files Browse the repository at this point in the history
* Split out confusing path combination logic to separate method

* Fix argument type
  • Loading branch information
malthe committed Feb 1, 2022
1 parent 89420df commit 4dcc35e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions airflow/providers/http/hooks/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def run(

session = self.get_conn(headers)

if self.base_url and not self.base_url.endswith('/') and endpoint and not endpoint.startswith('/'):
url = self.base_url + '/' + endpoint
else:
url = (self.base_url or '') + (endpoint or '')
url = self.url_from_endpoint(endpoint)

if self.method == 'GET':
# GET uses params
Expand Down Expand Up @@ -215,6 +212,12 @@ def run_with_advanced_retry(self, _retry_args: Dict[Any, Any], *args: Any, **kwa

return self._retry_obj(self.run, *args, **kwargs)

def url_from_endpoint(self, endpoint: Optional[str]) -> str:
"""Combine base url with endpoint"""
if self.base_url and not self.base_url.endswith('/') and endpoint and not endpoint.startswith('/'):
return self.base_url + '/' + endpoint
return (self.base_url or '') + (endpoint or '')

def test_connection(self):
"""Test HTTP Connection"""
try:
Expand Down

0 comments on commit 4dcc35e

Please sign in to comment.