|
7 | 7 | from dataclasses import dataclass |
8 | 8 | import html.parser |
9 | 9 | import debug |
| 10 | +import filemagic as mFile |
10 | 11 | from typing import TYPE_CHECKING |
11 | 12 |
|
12 | 13 | if TYPE_CHECKING: |
@@ -48,23 +49,17 @@ def handle_urlreq(ph: 'ProxyHandler', pr: urllib.parse.ParseResult, tag: str): |
48 | 49 | if not gotVU.callOk: |
49 | 50 | return UrlReqResp(gotVU.callOk, gotVU.statusCode, gotVU.statusMsg) |
50 | 51 | try: |
51 | | - hUA = ph.headers.get('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0') |
52 | | - hAL = ph.headers.get('Accept-Language', "en-US,en;q=0.9") |
53 | | - hA = ph.headers.get('Accept', "text/html,*/*") |
| 52 | + hUA = ph.headers.get('User-Agent', None) |
| 53 | + hAL = ph.headers.get('Accept-Language', None) |
| 54 | + hA = ph.headers.get('Accept', None) |
54 | 55 | headers = { |
55 | 56 | 'User-Agent': hUA, |
56 | 57 | 'Accept': hA, |
57 | 58 | 'Accept-Language': hAL |
58 | 59 | } |
59 | | - req = urllib.request.Request(url, headers=headers) |
60 | 60 | # Get requested url |
61 | | - print(f"DBUG:{tag}:Req:{req.full_url}:{req.headers}") |
62 | | - with urllib.request.urlopen(req, timeout=10) as response: |
63 | | - contentData = response.read().decode('utf-8') |
64 | | - statusCode = response.status or 200 |
65 | | - contentType = response.getheader('Content-Type') or 'text/html' |
66 | | - debug.dump({ 'url': req.full_url, 'headers': req.headers, 'ctype': contentType }, { 'cdata': contentData }) |
67 | | - return UrlReqResp(True, statusCode, "", contentType, contentData) |
| 61 | + gotFile = mFile.get_file(url, tag, "text/html", headers) |
| 62 | + return UrlReqResp(gotFile.callOk, gotFile.statusCode, gotFile.statusMsg, gotFile.contentType, gotFile.contentData.decode('utf-8')) |
68 | 63 | except Exception as exc: |
69 | 64 | return UrlReqResp(False, 502, f"WARN:{tag}:Failed:{exc}") |
70 | 65 |
|
|
0 commit comments