eth-stat-syncer

Cache live EVM blockchain stats
git clone git://holbrook.no/eth-stat-syncer.git
Log | Files | Refs

commit 26b01099eb0be264bdf0fce69a2178d3ce394ac0
parent 212b06ea5cadc8e6ed9472c5c20b379da530ed4d
Author: lash <dev@holbrook.no>
Date:   Tue,  8 Mar 2022 10:17:01 +0000

Improve accept handling in server

Diffstat:
Meth_stat_syncer/runnable/server.py | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/eth_stat_syncer/runnable/server.py b/eth_stat_syncer/runnable/server.py @@ -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