File size: 1,743 Bytes
083ada9
fd71b23
083ada9
 
 
ce65c89
 
 
 
 
 
 
 
083ada9
 
fd71b23
083ada9
cbca33d
e340c17
 
cbca33d
 
e340c17
 
cbca33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
083ada9
e340c17
 
 
 
 
 
 
 
fd71b23
e340c17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)

@app.route('/')
def home():
    return "Welcome to the Flask URL Fetcher!"

@app.route('/fetch', methods=['POST'])
def fetch_url_content():
    data = request.json
    target_url = data.get('url')
    if not target_url:
        return jsonify({"error": "No URL provided"}), 400

    try:
        # Make the GET request to the target URL (raw Pastebin link)
        response = requests.get(target_url, headers={
            "Cache-Control": "no-cache",
            "Pragma": "no-cache",
            "Accept": "text/plain"  # Ensure we get the raw plain text response
        })

        if response.status_code == 200:
            return jsonify({
                "status_code": response.status_code,
                "content": response.text  # Raw content from Pastebin
            })
        else:
            # Return detailed error info if status code is not 200
            return jsonify({
                "error": "Failed to fetch content",
                "status_code": response.status_code,
                "response_text": response.text
            }), 500
    except requests.exceptions.RequestException as e:
        # Capture and log any exception that occurs during the request
        return jsonify({"error": f"Request failed: {str(e)}"}), 500

# Prevent caching for responses from this Flask app itself
@app.after_request
def add_no_cache_headers(response):
    response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "-1"
    return response

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=7860)