manage json decode error, and add method OPTIONS (http request)
This commit is contained in:
parent
a9d4bbffcd
commit
3b901be756
1 changed files with 33 additions and 10 deletions
|
@ -199,7 +199,11 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return None
|
return None
|
||||||
msg = self.rfile.read(sizemsg)
|
msg = self.rfile.read(sizemsg)
|
||||||
|
try:
|
||||||
msgjson = json.loads(msg.decode())
|
msgjson = json.loads(msg.decode())
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
logging.error("Received request with json (%s)" % str(e))
|
||||||
|
return None
|
||||||
return msgjson
|
return msgjson
|
||||||
|
|
||||||
def _command_log(self):
|
def _command_log(self):
|
||||||
|
@ -442,6 +446,14 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler):
|
||||||
logging.debug('delete recieved!')
|
logging.debug('delete recieved!')
|
||||||
self.send_error(404, 'File Not Found: %s' % self.path)
|
self.send_error(404, 'File Not Found: %s' % self.path)
|
||||||
|
|
||||||
|
def do_OPTIONS(self):
|
||||||
|
""" request OPTIONS received """
|
||||||
|
self.send_response(200, "ok")
|
||||||
|
self.send_header('Access-Control-Allow-Origin', '*')
|
||||||
|
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
|
||||||
|
self.send_header("Access-Control-Allow-Headers", "*")
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
|
||||||
class khaganatHTTPServer(http.server.HTTPServer):
|
class khaganatHTTPServer(http.server.HTTPServer):
|
||||||
"""
|
"""
|
||||||
|
@ -778,6 +790,13 @@ class Manager():
|
||||||
self.users = {}
|
self.users = {}
|
||||||
self.passwordfile = None
|
self.passwordfile = None
|
||||||
self.serverHttp = None
|
self.serverHttp = None
|
||||||
|
self.port = 8000
|
||||||
|
self.address = ''
|
||||||
|
self.keyfile = 'crt/key.pem'
|
||||||
|
self.certfile = 'crt/cert.pem'
|
||||||
|
self.ca_cert = 'crt/ca_cert.crt'
|
||||||
|
self.authentification = False
|
||||||
|
self.method = 'http'
|
||||||
|
|
||||||
def load_config(self, filecfg):
|
def load_config(self, filecfg):
|
||||||
if filecfg is None:
|
if filecfg is None:
|
||||||
|
@ -812,23 +831,23 @@ class Manager():
|
||||||
try:
|
try:
|
||||||
self.port = int(config[name]['port'])
|
self.port = int(config[name]['port'])
|
||||||
except (TypeError, KeyError, ValueError):
|
except (TypeError, KeyError, ValueError):
|
||||||
self.port = 8000
|
pass
|
||||||
try:
|
try:
|
||||||
self.address = config[name]['address']
|
self.address = config[name]['address']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.address = ''
|
pass
|
||||||
try:
|
try:
|
||||||
self.keyfile = config[name]['keyfile']
|
self.keyfile = config[name]['keyfile']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.keyfile = 'crt/key.pem'
|
pass
|
||||||
try:
|
try:
|
||||||
self.certfile = config[name]['certfile']
|
self.certfile = config[name]['certfile']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.certfile = 'crt/cert.pem'
|
pass
|
||||||
try:
|
try:
|
||||||
self.ca_cert = config[name]['ca_cert']
|
self.ca_cert = config[name]['ca_cert']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.ca_cert = 'crt/ca_cert.crt'
|
pass
|
||||||
try:
|
try:
|
||||||
tmp = config[name]['authentification']
|
tmp = config[name]['authentification']
|
||||||
if tmp.upper().strip() == 'YES':
|
if tmp.upper().strip() == 'YES':
|
||||||
|
@ -836,17 +855,21 @@ class Manager():
|
||||||
else:
|
else:
|
||||||
self.authentification = False
|
self.authentification = False
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.authentification = False
|
pass
|
||||||
try:
|
try:
|
||||||
self.passwordfile = config[name]['passwordfile']
|
self.passwordfile = config[name]['passwordfile']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.passwordfile = None
|
pass
|
||||||
try:
|
try:
|
||||||
self.method = config[name]['method']
|
self.method = config[name]['method']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
self.method = 'http'
|
pass
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
head, value = name.split(':', maxsplit=1)
|
head, value = name.split(':', maxsplit=1)
|
||||||
|
except ValueError:
|
||||||
|
logging.warning("ignore bad parameter '%s'" % (name))
|
||||||
|
continue
|
||||||
if head == 'command' and 'command' in config[name]:
|
if head == 'command' and 'command' in config[name]:
|
||||||
logging.debug("read command '%s'" % name)
|
logging.debug("read command '%s'" % name)
|
||||||
if 'path' in config[name]:
|
if 'path' in config[name]:
|
||||||
|
|
Loading…
Reference in a new issue