Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Commit 3c33e72

Browse files
committed
1. (for developer) dump all traffic 2. ready for twitter
1 parent 26e1d09 commit 3c33e72

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

EasyWebsiteMirror.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
os.chdir(os.path.dirname(__file__))
66
import traceback
7+
import pickle
78
from datetime import datetime, timedelta
89
import re
910
import base64
1011
import zlib
12+
import gzip
1113
from time import time
1214
from html import escape as html_escape
1315
import threading
@@ -42,7 +44,7 @@
4244
errprint('Can Not Create Local File Cache: ', e, ' local file cache is disabled automatically.')
4345
local_cache_enable = False
4446

45-
__VERSION__ = '0.18.5-dev'
47+
__VERSION__ = '0.18.6-dev'
4648
__author__ = 'Aploium <i@z.codes>'
4749

4850
# ########## Basic Init #############
@@ -74,7 +76,6 @@
7476
request_local.start_time = None
7577
request_local.cur_mime = ''
7678
request_local.cache_control = ''
77-
request_local.remote_domain = ''
7879

7980
# ########## Handle dependencies #############
8081
if not enable_static_resource_CDN:
@@ -1092,15 +1093,17 @@ def request_remote_site_and_parse(actual_request_url):
10921093
dbgprint('CacheHit,Return')
10931094
if request_local.start_time is not None:
10941095
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
10961097

10971098
try: # send request to remote server
1099+
1100+
data = client_requests_bin_rewrite(request.get_data())
10981101
# server's request won't follow 301 or 302 redirection
10991102
r, req_time = send_request(
11001103
actual_request_url,
11011104
method=request.method,
11021105
headers=client_header,
1103-
data=client_requests_bin_rewrite(request.get_data()),
1106+
data=data # client_requests_bin_rewrite(request.get_data()),
11041107
)
11051108
except Exception as e:
11061109
errprint(e) # ERROR :( so sad
@@ -1144,6 +1147,16 @@ def request_remote_site_and_parse(actual_request_url):
11441147
resp.headers.add('X-CP-Time', "%.4f" % (time() - request_local.start_time - req_time))
11451148
resp.headers.add('X-EWM-Version', __VERSION__)
11461149

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+
11471160
return resp
11481161

11491162

config.sample.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@
448448
# It will slow down the calculate speed, set to None in production environment, or an string to trace
449449
developer_string_trace = None
450450

451+
# v0.18.6+ Dump all traffics (exclude cached)
452+
# If set to True, all traffic objects would be dumped to an pickle file,
453+
# Include: time, flask request object, requests response object, our server's (flask) response object
454+
developer_dump_all_traffics = False
455+
456+
451457
# #####################################################
452458
# ###################### SAMPLE #######################
453459
# #####################################################

0 commit comments

Comments
 (0)