from flask import Flask, request, Response import requests app = Flask(__name__) # HTML form template to allow user input html_form = '''
''' @app.route('/') def home(): # Display the form for URL input return html_form @app.route('/proxy') def proxy(): # Get the URL from the user's input url = request.args.get('url') if not url: return "No URL provided", 400 # Validate URL (must start with http:// or https:// for security) if not (url.startswith("http://") or url.startswith("https://")): return "Invalid URL. Please include http:// or https://", 400 try: # Fetch the content from the specified URL response = requests.get(url) response.raise_for_status() # Ensure the request was successful # Return the fetched content as a response to the user return Response(response.content, content_type=response.headers['Content-Type']) except requests.RequestException as e: # Handle errors in fetching the page return f"Error fetching the page: {e}" if __name__ == "__main__": # Run the Flask app on port 7860 app.run(host="0.0.0.0", port=7860)