Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
from urllib.parse import urlencode, quote_plus, urlparse
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
if
|
16 |
-
|
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:
|
25 |
-
# Return error message in case of request failure
|
26 |
-
return f"An error occurred while forwarding parameters: {str(e)}"
|
27 |
-
|
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 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit.components.v1 import html
|
|
|
3 |
|
4 |
+
# Function to extract query parameters
|
5 |
+
def get_query_params():
|
6 |
+
# Streamlit provides st.experimental_get_query_params() to access query parameters
|
7 |
+
return st.experimental_get_query_params()
|
8 |
|
9 |
+
# Main function where we handle the redirect
|
10 |
+
def main():
|
11 |
+
# Get query parameters
|
12 |
+
query_params = get_query_params()
|
13 |
+
|
14 |
+
# Check if 'param1' exists in the query parameters
|
15 |
+
if 'param1' in query_params:
|
16 |
+
# Extract the first value of 'param1'
|
17 |
+
redirect_url = query_params['param1'][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Use JavaScript to redirect to the URL provided in 'param1'
|
20 |
+
js = f"""
|
21 |
+
<script>
|
22 |
+
window.location.href = "{redirect_url}";
|
23 |
+
</script>
|
24 |
+
"""
|
25 |
+
html(js) # Use Streamlit's HTML component to run the JavaScript
|
26 |
+
else:
|
27 |
+
# If 'param1' is not present, display a message
|
28 |
+
st.write("No redirect URL provided in query parameters.")
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
main()
|