Improve accept handling in server

This commit is contained in:
lash 2022-03-08 10:17:01 +00:00
parent 212b06ea5c
commit 26b01099eb
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
1 changed files with 17 additions and 2 deletions

View File

@ -25,7 +25,7 @@ default_config_dir = os.environ.get('CONFINI_DIR', './config')
argparser = argparse.ArgumentParser()
argparser.add_argument('-c', '--config', dest='c', default=default_config_dir, type=str, help='rpc provider')
argparser.add_argument('--host', type=str, help='httpd host')
argparser.add_argument('--port', type=str, help='httpd port')
argparser.add_argument('--port', type=int, help='httpd port')
argparser.add_argument('--store-dir', dest='store_dir', type=str, help='syncerd data store base directory')
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
argparser.add_argument('-v', action='store_true', help='be verbose')
@ -61,7 +61,22 @@ class StatRequestHandler(BaseHTTPRequestHandler):
self.end_headers()
return
if 'application/json' not in self.headers.get('Accept').split(','):
accept = ['application/json']
try:
accept = self.headers.get('Accept').split(',')
except AttributeError:
pass
logg.debug('accept is {}'.format(accept))
nocomprendo = True
if '*/*' in accept:
nocomprendo = False
elif 'application/json' in accept:
nocomprendo = False
elif '*' in accept:
nocomprendo = False
if nocomprendo:
self.send_response(400, 'me json only speak')
self.end_headers()
return