Skip to content

Commit baf2c1b

Browse files
author
Joel Collins
committed
Support overriding protocol in ResourceURL
1 parent e51b2e0 commit baf2c1b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/labthings/utilities.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,21 @@ class ResourceURL(UserString):
4848
Behaves as a Python string.
4949
"""
5050

51-
def __init__(self, path: str, external: bool = True):
51+
def __init__(self, path: str, external: bool = True, protocol: str = ""):
5252
self.path = path
5353
self.external = external
54+
# Strip :// if the user mistakenly included it in the argument
55+
self.protocol = protocol.rstrip("://")
5456
UserString.__init__(self, path)
5557

5658
@property
5759
def data(self):
5860
if self.external and has_request_context():
5961
prefix = request.host_url.rstrip("/")
62+
# Optional protocol override
63+
if self.protocol:
64+
# Strip old protocol and replace with custom protocol
65+
prefix = self.protocol + "://" + prefix.split("://")[1]
6066
else:
6167
prefix = ""
6268
return prefix + self.path

0 commit comments

Comments
 (0)