Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,15 +10,15 @@ def forward_parameters(target_url, extra_params):
|
|
| 10 |
:param extra_params: A dictionary of additional parameters to forward.
|
| 11 |
:return: The response from the target URL.
|
| 12 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
# Validate the target URL
|
| 15 |
-
parsed_url = urlparse(target_url)
|
| 16 |
-
if not parsed_url.scheme in ['http', 'https']:
|
| 17 |
-
return "Invalid URL: URLs must start with http:// or https://"
|
| 18 |
-
|
| 19 |
-
# Construct the full URL with extra parameters
|
| 20 |
-
encoded_params = urlencode(extra_params, quote_via=quote_plus)
|
| 21 |
-
full_url = f"{target_url}?{encoded_params}" if encoded_params else target_url
|
| 22 |
response = requests.get(full_url) # Using GET request for simplicity
|
| 23 |
return response.text
|
| 24 |
except requests.exceptions.RequestException as e:
|
|
@@ -28,26 +28,20 @@ def forward_parameters(target_url, extra_params):
|
|
| 28 |
# Streamlit interface
|
| 29 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
| 30 |
|
| 31 |
-
#
|
| 32 |
params = st.query_params
|
| 33 |
|
| 34 |
-
|
| 35 |
-
st.write("Received parameters:", params)
|
| 36 |
-
|
| 37 |
-
target_url = params.get('param1', [None])[0] # Extract the target URL
|
| 38 |
|
| 39 |
if target_url:
|
| 40 |
-
# Remove 'param1'
|
| 41 |
forwarded_params = {k: v for k, v in params.items() if k != 'param1'}
|
| 42 |
response = forward_parameters(target_url, forwarded_params)
|
| 43 |
-
st.text_area("Response from Target URL", value=response, height=300
|
| 44 |
else:
|
| 45 |
-
st.error("
|
| 46 |
st.markdown("""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
Example: `?param1=http://example.com¶m2=value`
|
| 51 |
-
|
| 52 |
-
This will forward `param2=value` to `http://example.com`.
|
| 53 |
""")
|
|
|
|
| 10 |
:param extra_params: A dictionary of additional parameters to forward.
|
| 11 |
:return: The response from the target URL.
|
| 12 |
"""
|
| 13 |
+
# Validate the target URL
|
| 14 |
+
parsed_url = urlparse(target_url)
|
| 15 |
+
if parsed_url.scheme not in ['http', 'https']:
|
| 16 |
+
return f"Invalid URL: '{target_url}'. URLs must start with http:// or https://"
|
| 17 |
+
|
| 18 |
+
# Construct the full URL with extra parameters
|
| 19 |
+
encoded_params = urlencode(extra_params, quote_via=quote_plus)
|
| 20 |
+
full_url = f"{target_url}?{encoded_params}" if encoded_params else target_url
|
| 21 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
response = requests.get(full_url) # Using GET request for simplicity
|
| 23 |
return response.text
|
| 24 |
except requests.exceptions.RequestException as e:
|
|
|
|
| 28 |
# Streamlit interface
|
| 29 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
| 30 |
|
| 31 |
+
# Accessing the query parameters
|
| 32 |
params = st.query_params
|
| 33 |
|
| 34 |
+
target_url = params.get('param1', [None])[0]
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if target_url:
|
| 37 |
+
# Remove 'param1' from the parameters to be forwarded
|
| 38 |
forwarded_params = {k: v for k, v in params.items() if k != 'param1'}
|
| 39 |
response = forward_parameters(target_url, forwarded_params)
|
| 40 |
+
st.text_area("Response from Target URL", value=response, height=300)
|
| 41 |
else:
|
| 42 |
+
st.error("Please provide a target URL using `?param1=URL` in the query string.")
|
| 43 |
st.markdown("""
|
| 44 |
+
**Example usage:**
|
| 45 |
+
|
| 46 |
+
Append `?param1=http://example.com¶m2=value` to the query string in the address bar. This will forward `param2=value` to `http://example.com`.
|
|
|
|
|
|
|
|
|
|
| 47 |
""")
|