Improve accept handling in server
This commit is contained in:
parent
212b06ea5c
commit
26b01099eb
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user