Browse Source

use text/plain rather than text/csv

master
nervuri 3 months ago
parent
commit
f25e2fa44c
  1. 43
      trust-seeker

43
trust-seeker

@ -53,7 +53,7 @@ def eprint(*args, **kwargs):
# Outputs response in the appropriate format
def respond(response: str, status='success', mime_type: str = ''):
def respond(response: str, status='success', mime_type: str = 'text/plain'):
# Status codes for CLI, Gemini and HTTP.
# Inspired by Convergence's Notary Protocol:
@ -83,32 +83,23 @@ def respond(response: str, status='success', mime_type: str = ''):
status_code = status_codes[status][0]
# TODO: find a better way
if response[:6] == 'Usage:':
mime_type = 'text/plain'
# build CSV response - https://tools.ietf.org/html/rfc4180
if not mime_type:
mime_type = 'text/csv'
if mime_type == 'text/csv':
if type(response) == str:
if ',' in response and '\n' not in response:
response = '"' + response + '"'
if response[:7] != 'status,':
response = 'status,response\n' + status + ',' + response
elif type(response) == list:
csv = 'status,fingerprint,expires,tls_version,cipher_suite,first_seen,last_seen,seen_count' # CSV header
if mime_type == 'text/plain':
if type(response) == list:
formatted_response = 'status=' + status
# Let user know if response contains multiple pins.
# TODO: Add support for multiple pins.
if len(response) > 1:
formatted_response += os.linesep + 'number_of_pins=' + str(len(response))
for pin in response:
csv += '\n' + status +\
',' + pin['fingerprint'] +\
',' + str(pin['expires']) +\
',' + str(pin['tls_version']) +\
',' + pin['cipher_suite'] +\
',' + str(pin['first_seen']) +\
',' + str(pin['last_seen']) +\
',' + str(pin['seen_count'])
response = csv
formatted_response += os.linesep + 'fingerprint=' + pin['fingerprint'] +\
os.linesep + 'expires=' + str(pin['expires']) +\
os.linesep + 'tls_version=' + str(pin['tls_version']) +\
os.linesep + 'cipher_suite=' + pin['cipher_suite'] +\
os.linesep + 'first_seen=' + str(pin['first_seen']) +\
os.linesep + 'last_seen=' + str(pin['last_seen']) +\
os.linesep + 'seen_count=' + str(pin['seen_count'])
break
response = formatted_response
# No CGI
if remote_protocol == '':

Loading…
Cancel
Save