aiohttp-debugtoolbar
aiohttp-debugtoolbar copied to clipboard
Plain text output for command line user agents
I've just been building a restful API and am testing it with curl.
I have debugtoolbar enabled and 500 errors come through as a full web page which isn't at all easy to read.
The obvious solution is to disable debugtoolbar but it would still be nice to show plain text output for obvious CLI requests eg. curl, wget, httpie in case people use curl with dbtb switched on.
Alternatively there could be a white list of browser user-agents to show HTML response for or use content-type, but that all seems error prone.
Good idea, would you like to create PR with content type check?
also there is option that can disable interception of exception https://github.com/aio-libs/aiohttp-debugtoolbar/blob/055f1cfc37b8f8c6f1bb3bf7cf9ad2b369a26e98/aiohttp_debugtoolbar/middlewares.py#L25
I'll create a PR if I get a chance, however I really think User-Agent is a better field to decide with than Content-Type.
- That's kind of the point in
User-Agent- to tell the server what kind of application is making the request. - It's likely that when using CLI apps to make requests people will mess with the
content-typeas it's regularly used by servers to decide what to do.
In time I guess we could use content-type checking too, but let's do the simplest thing first then make it more complicated when we have to.
I also noticed that even with debugtoolbar switched off (or I guess exception interception disabled) the debug response from aiohttp is encoded as HTML (even if it's very simple) so this change would be useful even in that situation.