hugapi / hug

Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.
MIT License
6.86k stars 388 forks source link

Is there any way to set the content-type dynamically inside the handler? #879

Open makkalot opened 3 years ago

makkalot commented 3 years ago

I'm having this interesting issue where I have this handler which returns json normally but on certain condition there's requirement where I need to return html response back. Therefore in my handler I need to figure out when to return json and when to return html response. I naively tried :

response.status = HTTP_OK       
response.content_type = 'text/html'

but seems the output formatters are overriding this. Any ideas how to solve it ?