Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,13 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
from urllib.parse import urlencode, quote_plus, urlparse
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def forward_parameters(target_url, extra_params):
|
6 |
"""
|
7 |
Forward parameters to the target URL and return the response.
|
@@ -10,12 +17,10 @@ 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 |
-
# Ensure the target URL has a valid scheme
|
15 |
-
parsed_url = urlparse(target_url)
|
16 |
-
if not parsed_url.scheme:
|
17 |
-
return "Invalid URL: No scheme supplied. URLs must start with http:// or https://"
|
18 |
-
|
19 |
# Construct the full URL with extra parameters
|
20 |
full_url = f"{target_url}?{urlencode(extra_params, quote_via=quote_plus)}"
|
21 |
response = requests.get(full_url) # Using GET request for simplicity
|
@@ -28,10 +33,9 @@ def forward_parameters(target_url, extra_params):
|
|
28 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
29 |
|
30 |
# Correctly accessing the query parameters
|
31 |
-
params = st.query_params
|
32 |
-
st.write("Received parameters:", params) # Debug: Log received parameters
|
33 |
|
34 |
-
target_url = params.get('param1', [None])[0]
|
35 |
|
36 |
if target_url:
|
37 |
# Remove 'param1' to forward the remaining parameters
|
|
|
2 |
import requests
|
3 |
from urllib.parse import urlencode, quote_plus, urlparse
|
4 |
|
5 |
+
def is_valid_url(url):
|
6 |
+
"""
|
7 |
+
Checks if the URL has a valid scheme.
|
8 |
+
"""
|
9 |
+
parsed_url = urlparse(url)
|
10 |
+
return parsed_url.scheme in ['http', 'https']
|
11 |
+
|
12 |
def forward_parameters(target_url, extra_params):
|
13 |
"""
|
14 |
Forward parameters to the target URL and return the response.
|
|
|
17 |
:param extra_params: A dictionary of additional parameters to forward.
|
18 |
:return: The response from the target URL.
|
19 |
"""
|
20 |
+
if not is_valid_url(target_url):
|
21 |
+
return "Invalid URL: No scheme supplied. URLs must start with http:// or https://"
|
22 |
+
|
23 |
try:
|
|
|
|
|
|
|
|
|
|
|
24 |
# Construct the full URL with extra parameters
|
25 |
full_url = f"{target_url}?{urlencode(extra_params, quote_via=quote_plus)}"
|
26 |
response = requests.get(full_url) # Using GET request for simplicity
|
|
|
33 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
34 |
|
35 |
# Correctly accessing the query parameters
|
36 |
+
params = st.query_params
|
|
|
37 |
|
38 |
+
target_url = params.get('param1', [None])[0]
|
39 |
|
40 |
if target_url:
|
41 |
# Remove 'param1' to forward the remaining parameters
|