Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out confusing path combination logic to separate method #21247

Merged
merged 2 commits into from
Feb 1, 2022
Merged
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
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