|
4 | 4 |
|
5 | 5 | os.chdir(os.path.dirname(__file__)) |
6 | 6 | import traceback |
| 7 | +import pickle |
7 | 8 | from datetime import datetime, timedelta |
8 | 9 | import re |
9 | 10 | import base64 |
10 | 11 | import zlib |
| 12 | +import gzip |
11 | 13 | from time import time |
12 | 14 | from html import escape as html_escape |
13 | 15 | import threading |
|
42 | 44 | errprint('Can Not Create Local File Cache: ', e, ' local file cache is disabled automatically.') |
43 | 45 | local_cache_enable = False |
44 | 46 |
|
45 | | -__VERSION__ = '0.18.5-dev' |
| 47 | +__VERSION__ = '0.18.6-dev' |
46 | 48 | __author__ = 'Aploium <i@z.codes>' |
47 | 49 |
|
48 | 50 | # ########## Basic Init ############# |
|
74 | 76 | request_local.start_time = None |
75 | 77 | request_local.cur_mime = '' |
76 | 78 | request_local.cache_control = '' |
77 | | -request_local.remote_domain = '' |
78 | 79 |
|
79 | 80 | # ########## Handle dependencies ############# |
80 | 81 | if not enable_static_resource_CDN: |
@@ -1092,15 +1093,17 @@ def request_remote_site_and_parse(actual_request_url): |
1092 | 1093 | dbgprint('CacheHit,Return') |
1093 | 1094 | if request_local.start_time is not None: |
1094 | 1095 | resp.headers.set('X-CP-Time', "%.4f" % (time() - request_local.start_time)) |
1095 | | - return resp # If cache hit, just skip next steps |
| 1096 | + return resp # If cache hit, just skip the next steps |
1096 | 1097 |
|
1097 | 1098 | try: # send request to remote server |
| 1099 | + |
| 1100 | + data = client_requests_bin_rewrite(request.get_data()) |
1098 | 1101 | # server's request won't follow 301 or 302 redirection |
1099 | 1102 | r, req_time = send_request( |
1100 | 1103 | actual_request_url, |
1101 | 1104 | method=request.method, |
1102 | 1105 | headers=client_header, |
1103 | | - data=client_requests_bin_rewrite(request.get_data()), |
| 1106 | + data=data # client_requests_bin_rewrite(request.get_data()), |
1104 | 1107 | ) |
1105 | 1108 | except Exception as e: |
1106 | 1109 | errprint(e) # ERROR :( so sad |
@@ -1144,6 +1147,16 @@ def request_remote_site_and_parse(actual_request_url): |
1144 | 1147 | resp.headers.add('X-CP-Time', "%.4f" % (time() - request_local.start_time - req_time)) |
1145 | 1148 | resp.headers.add('X-EWM-Version', __VERSION__) |
1146 | 1149 |
|
| 1150 | + if developer_dump_all_traffics: |
| 1151 | + if not os.path.exists('traffic'): |
| 1152 | + os.mkdir('traffic') |
| 1153 | + _time_str = datetime.now().strftime('traffic_%Y-%m-%d_%H:%M:%S') |
| 1154 | + try: |
| 1155 | + pickle.dump((_time_str, repr(request.url), repr(request.headers), repr(request.get_data()), r, resp), |
| 1156 | + gzip.open(os.path.join('traffic', _time_str + '.dump'), 'wb')) |
| 1157 | + except: |
| 1158 | + traceback.print_exc() |
| 1159 | + |
1147 | 1160 | return resp |
1148 | 1161 |
|
1149 | 1162 |
|
|
0 commit comments