From d1ea3c958b7b12bdd2f1d91bcc19a34b121f3ed7 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 10 Jul 2019 08:25:52 +0200 Subject: [PATCH] chg: [aks] HKP improvement (still WiP) --- bin/aks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/aks.py b/bin/aks.py index 7790ed9..25dfade 100644 --- a/bin/aks.py +++ b/bin/aks.py @@ -1,4 +1,4 @@ -from flask import Flask, request, abort +from flask import Flask, request, abort, Response import configparser import redis @@ -18,6 +18,10 @@ def index(): @app.route('/pks/lookup') def pks(): + if (request.headers.get('Content-Type') is None) or (request.headers.get('ContentType') == 'text/plain') or (request.headers.get('ContentType') == 'application/pgp-keys'): + machinereadable = True + else: + machinereadable = False op = request.args.get('op').lower() if not (op == 'get' or op == 'index'): abort(501) @@ -27,7 +31,7 @@ def pks(): if op == 'get' and search.lower().startswith('0x'): print('Get for {}'.format(search)) if backend.exists('k:{}'.format(search.lower()[2:])): - return '{}'.format(backend.get('k:{}'.format(search.lower()[2:]))) + return Response('{}'.format(backend.get('k:{}'.format(search.lower()[2:]))), mimetype='application/pgp-keys') if op == 'index' and search.lower(): print('Searching for {}'.format(search)) ret = backend.scan(0, 'ue:*{}'.format(search), count=100)