Skip to content

Commit fc4a4db

Browse files
committed
Patch abs_url() to check if input url is already absolute
Patch RestSession.abs_url() so that it will not modify an input URL if the input is already an absolute URL.
1 parent f558af4 commit fc4a4db

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ciscosparkapi/restsession.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,23 @@ def update_headers(self, headers):
184184
assert isinstance(headers, dict)
185185
self._req_session.headers.update(headers)
186186

187-
def abs_url(self, relative_url):
187+
def abs_url(self, url):
188188
"""Convert a relative URL to an absolute URL.
189189
190190
Args:
191-
relative_url(basestring): A relative URL.
191+
url(basestring): A relative URL.
192192
193193
Returns:
194194
str: An absolute URL.
195195
196196
"""
197-
return urllib.parse.urljoin(str(self.base_url),
198-
str(relative_url))
197+
parsed_url = urllib.parse.urlparse(url)
198+
if not parsed_url.scheme and not parsed_url.netloc:
199+
# url is a relative URL; combine with base_url
200+
return urllib.parse.urljoin(str(self.base_url), str(url))
201+
else:
202+
# url is already an absolute URL; return as is
203+
return url
199204

200205
def request(self, method, relative_url, erc, **kwargs):
201206
"""Abstract base method for making requests to the Cisco Spark APIs.

0 commit comments

Comments
 (0)