Skip to content

Commit 2607bcf

Browse files
authored
fix: (CDK) (HttpRequester) - fix trailing slash for url_base when no path has been provided (#412)
1 parent 450a845 commit 2607bcf

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

airbyte_cdk/sources/declarative/requesters/http_requester.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_url_base(
132132
stream_slice=stream_slice,
133133
next_page_token=next_page_token,
134134
)
135-
return os.path.join(self._url_base.eval(self.config, **interpolation_context), EmptyString)
135+
return str(self._url_base.eval(self.config, **interpolation_context))
136136

137137
def get_path(
138138
self,
@@ -370,13 +370,18 @@ def _join_url(cls, url_base: str, path: str) -> str:
370370
Example:
371371
1) _join_url("https://example.com/api/", "endpoint") >> 'https://example.com/api/endpoint'
372372
2) _join_url("https://example.com/api", "/endpoint") >> 'https://example.com/api/endpoint'
373-
3) _join_url("https://example.com/api/", "") >> 'https://example.com/api'
373+
3) _join_url("https://example.com/api/", "") >> 'https://example.com/api/'
374374
4) _join_url("https://example.com/api", None) >> 'https://example.com/api'
375375
"""
376376

377377
# return a full-url if provided directly from interpolation context
378378
if path == EmptyString or path is None:
379-
return url_base.rstrip("/")
379+
return url_base
380+
else:
381+
# since we didn't provide a full-url, the url_base might not have a trailing slash
382+
# so we join the url_base and path correctly
383+
if not url_base.endswith("/"):
384+
url_base += "/"
380385

381386
return urljoin(url_base, path)
382387

unit_tests/sources/declarative/requesters/test_http_requester.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_http_requester():
121121
parameters={},
122122
)
123123

124-
assert requester.get_url_base() == "https://airbyte.io/"
124+
assert requester.get_url_base() == "https://airbyte.io"
125125
assert (
126126
requester.get_path(stream_state={}, stream_slice=stream_slice, next_page_token={})
127127
== "v1/1234"
@@ -145,9 +145,9 @@ def test_http_requester():
145145
@pytest.mark.parametrize(
146146
"test_name, base_url, expected_base_url",
147147
[
148-
("test_no_trailing_slash", "https://example.com", "https://example.com/"),
148+
("test_no_trailing_slash", "https://example.com", "https://example.com"),
149149
("test_with_trailing_slash", "https://example.com/", "https://example.com/"),
150-
("test_with_v1_no_trailing_slash", "https://example.com/v1", "https://example.com/v1/"),
150+
("test_with_v1_no_trailing_slash", "https://example.com/v1", "https://example.com/v1"),
151151
("test_with_v1_with_trailing_slash", "https://example.com/v1/", "https://example.com/v1/"),
152152
],
153153
)

0 commit comments

Comments
 (0)