|
from flask import Flask, request, Response |
|
import requests |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
html_form = ''' |
|
<form action="/proxy" method="get"> |
|
<label for="url">Enter URL:</label> |
|
<input type="text" id="url" name="url" placeholder="https://example.com" required> |
|
<button type="submit">Browse</button> |
|
</form> |
|
''' |
|
|
|
@app.route('/') |
|
def home(): |
|
|
|
return html_form |
|
|
|
@app.route('/proxy') |
|
def proxy(): |
|
|
|
url = request.args.get('url') |
|
if not url: |
|
return "No URL provided", 400 |
|
|
|
|
|
if not (url.startswith("http://") or url.startswith("https://")): |
|
return "Invalid URL. Please include http:// or https://", 400 |
|
|
|
try: |
|
|
|
response = requests.get(url) |
|
response.raise_for_status() |
|
|
|
|
|
return Response(response.content, content_type=response.headers['Content-Type']) |
|
|
|
except requests.RequestException as e: |
|
|
|
return f"Error fetching the page: {e}" |
|
|
|
if __name__ == "__main__": |
|
|
|
app.run(host="0.0.0.0", port=7860) |
|
|