aiohttp-debugtoolbar icon indicating copy to clipboard operation
aiohttp-debugtoolbar copied to clipboard

Plain text output for command line user agents

Open samuelcolvin opened this issue 8 years ago • 3 comments

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.

samuelcolvin avatar Jan 12 '17 17:01 samuelcolvin

Good idea, would you like to create PR with content type check?

jettify avatar Jan 12 '17 18:01 jettify

also there is option that can disable interception of exception https://github.com/aio-libs/aiohttp-debugtoolbar/blob/055f1cfc37b8f8c6f1bb3bf7cf9ad2b369a26e98/aiohttp_debugtoolbar/middlewares.py#L25

jettify avatar Jan 12 '17 18:01 jettify

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.

  1. That's kind of the point in User-Agent - to tell the server what kind of application is making the request.
  2. It's likely that when using CLI apps to make requests people will mess with the content-type as 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.

samuelcolvin avatar Jan 12 '17 19:01 samuelcolvin