demo-fastapi/ajal_demo/web.py
2023-05-16 23:25:15 -04:00

17 lines
595 B
Python

from .app import app
from fastapi.requests import Request
from fastapi.responses import PlainTextResponse
@app.get('/status')
@app.get('/status/')
def status(request: Request):
accepted_types = (s for s in request.headers.get('accept', '').split(','))
for accepted_type in accepted_types:
if ';' in accepted_type:
accepted_type, _ = accepted_type.split(';', 1)
if accepted_type.strip() in ['*/*', 'text/plain']:
break
if accepted_type.strip() == 'application/json':
return {'status': 'OK'}
return PlainTextResponse('OK')