@@ -161,3 +161,32 @@ class PlainRequest(BaseAnvilHttpRequest):
161161
162162 def get_url (self ):
163163 return f"{ self .API_HOST } /{ self .API_BASE } "
164+
165+
166+ class FullyQualifiedRequest (BaseAnvilHttpRequest ):
167+ """A request class that validates URLs are fully qualified and point to Anvil domains."""
168+
169+ VALID_HOSTS = [
170+ "https://app.useanvil.com" ,
171+ # Future Anvil specific URLs
172+ ]
173+
174+ def __init__ (self , client , options = None ):
175+ super ().__init__ (client , options )
176+
177+ def get_url (self ):
178+ return "" # Not used since we expect full URLs
179+
180+ def _validate_url (self , url ):
181+ if not any (url .startswith (host ) for host in self .VALID_HOSTS ):
182+ raise ValueError (
183+ f"URL must start with one of: { ', ' .join (self .VALID_HOSTS )} "
184+ )
185+
186+ def get (self , url , params = None , ** kwargs ):
187+ self ._validate_url (url )
188+ return super ().get (url , params , ** kwargs )
189+
190+ def post (self , url , data = None , ** kwargs ):
191+ self ._validate_url (url )
192+ return super ().post (url , data , ** kwargs )
0 commit comments