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):
|
||||
if not self.is_connect:
|
||||
if self.command == 'PUTMETA':
|
||||
self._prepare_custom_record(method=self.command, type_='metadata')
|
||||
self._special_request(method=self.command, type_='metadata')
|
||||
return
|
||||
# if self.command == 'PUTRES':
|
||||
# self._handle_custom_record(type_='resource')
|
||||
# self._special_request(type_='resource')
|
||||
# return
|
||||
|
||||
try:
|
||||
@ -137,7 +137,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
|
||||
|
||||
self._proxy_request()
|
||||
|
||||
def _handle_custom_record(self, method, type_):
|
||||
def _special_request(self, method, type_):
|
||||
raise Exception('Not supported')
|
||||
|
||||
def _proxy_request(self):
|
||||
|
@ -216,10 +216,12 @@ class WarcProxyHandler(warcprox.mitmproxy.MitmProxyHandler):
|
||||
|
||||
return recorded_url
|
||||
|
||||
def _handle_custom_record(self, method, type_):
|
||||
def _special_request(self, method, type_):
|
||||
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
|
||||
and 'Content-Type' in self.headers):
|
||||
request_data = self.rfile.read(int(self.headers['Content-Length']))
|
||||
|
||||
warcprox_meta = self.headers.get('Warcprox-Meta')
|
||||
@ -240,6 +242,9 @@ class WarcProxyHandler(warcprox.mitmproxy.MitmProxyHandler):
|
||||
self.send_error(400, 'Bad request')
|
||||
|
||||
self.end_headers()
|
||||
except:
|
||||
self.logger.error("uncaught except in _special_request", exc_info=True)
|
||||
raise
|
||||
|
||||
def log_error(self, fmt, *args):
|
||||
# logging better handled elsewhere?
|
||||
|
Loading…
x
Reference in New Issue
Block a user