mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
catch exception handling special request (currently that means PUTMETA)
This commit is contained in:
parent
f00602b764
commit
eb7de9d3f9
@ -117,10 +117,10 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
|
|||||||
def do_COMMAND(self):
|
def do_COMMAND(self):
|
||||||
if not self.is_connect:
|
if not self.is_connect:
|
||||||
if self.command == 'PUTMETA':
|
if self.command == 'PUTMETA':
|
||||||
self._prepare_custom_record(method=self.command, type_='metadata')
|
self._special_request(method=self.command, type_='metadata')
|
||||||
return
|
return
|
||||||
# if self.command == 'PUTRES':
|
# if self.command == 'PUTRES':
|
||||||
# self._handle_custom_record(type_='resource')
|
# self._special_request(type_='resource')
|
||||||
# return
|
# return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -137,7 +137,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
self._proxy_request()
|
self._proxy_request()
|
||||||
|
|
||||||
def _handle_custom_record(self, method, type_):
|
def _special_request(self, method, type_):
|
||||||
raise Exception('Not supported')
|
raise Exception('Not supported')
|
||||||
|
|
||||||
def _proxy_request(self):
|
def _proxy_request(self):
|
||||||
|
@ -216,30 +216,35 @@ class WarcProxyHandler(warcprox.mitmproxy.MitmProxyHandler):
|
|||||||
|
|
||||||
return recorded_url
|
return recorded_url
|
||||||
|
|
||||||
def _handle_custom_record(self, method, type_):
|
def _special_request(self, method, type_):
|
||||||
self.url = self.path
|
try:
|
||||||
|
self.url = self.path
|
||||||
|
|
||||||
if 'Content-Length' in self.headers and 'Content-Type' in self.headers:
|
if (method == 'PUTMETA' and 'Content-Length' in self.headers
|
||||||
request_data = self.rfile.read(int(self.headers['Content-Length']))
|
and 'Content-Type' in self.headers):
|
||||||
|
request_data = self.rfile.read(int(self.headers['Content-Length']))
|
||||||
|
|
||||||
warcprox_meta = self.headers.get('Warcprox-Meta')
|
warcprox_meta = self.headers.get('Warcprox-Meta')
|
||||||
|
|
||||||
rec_custom = RecordedUrl(url=self.url,
|
rec_custom = RecordedUrl(url=self.url,
|
||||||
request_data=request_data,
|
request_data=request_data,
|
||||||
response_recorder=None,
|
response_recorder=None,
|
||||||
remote_ip=b'',
|
remote_ip=b'',
|
||||||
warcprox_meta=warcprox_meta,
|
warcprox_meta=warcprox_meta,
|
||||||
content_type=self.headers['Content-Type'].encode('latin1'),
|
content_type=self.headers['Content-Type'].encode('latin1'),
|
||||||
custom_type=type_,
|
custom_type=type_,
|
||||||
method=method,
|
method=method,
|
||||||
status=204, size=len(request_data))
|
status=204, size=len(request_data))
|
||||||
|
|
||||||
self.server.recorded_url_q.put(rec_custom)
|
self.server.recorded_url_q.put(rec_custom)
|
||||||
self.send_response(204, 'OK')
|
self.send_response(204, 'OK')
|
||||||
else:
|
else:
|
||||||
self.send_error(400, 'Bad request')
|
self.send_error(400, 'Bad request')
|
||||||
|
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
except:
|
||||||
|
self.logger.error("uncaught except in _special_request", exc_info=True)
|
||||||
|
raise
|
||||||
|
|
||||||
def log_error(self, fmt, *args):
|
def log_error(self, fmt, *args):
|
||||||
# logging better handled elsewhere?
|
# logging better handled elsewhere?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user