New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verbose misses response body #282
Comments
You're using a version of gabbi that is about 2.5 years old. If you're able to upgrade and try the same test that would be helpful in trying to trace where the problem is. I'm pretty sure the version won't make a difference, but I'd like to remove that variable. Note that if no content-type is provided, or a content-type for which gabbi does not have a ContentHandler , then gabbi will not send a body. You can see that in your paste above because the request body is empty. If you need to be able to send other content-types there are ways to subclass ContentHandler (see: https://gabbi.readthedocs.io/en/latest/handlers.html ) Also could you tell me more about the server you are making your requests against? I've tried against a few different servers (both python and go-based, using both modern gabbi and the version you're running) and I'm unable to replicate the problem you are seeing. One thing that would be worth trying is replicating the request using curl in verbose mode to show the output gabbi should be showing. That will help to narrow things down. I think the curl would look something like this (including empty body based on no ContentHandler):
I hope we can work this out, but I need a bit more info to make any progress. |
I can not reproduce it with the latest version. |
That's something that's beyond my control. Which version the various linux distros choose to package is up to them and not something I'm involved with. If you'd like to see them be more up to date, opening a bug with them may help. The linux distros being out of date with regard to Python packages is a fairly common problem, big enough that people tend to install the Python packages they use regularly via |
no worries. thanks |
Sorry, I was wrong. I can reproduce the issue with the latest. As far as I can see it does not print the response body if a server does not set Content-type header. |
It also prints the following error if response content-type is "application/json" but the response body is just plain text:
|
I think it should apply the default content-type if the response does not contain it. It should be UTF-8 string by default, as far as I remember. |
Thanks, those are good clues as to what's going wrong. I think you're right: If it can't figure out what to show it should try to dump a string. I'll look into what it will take to do that. Will try to get to it tomorrow, but it may be a few days. |
I've started experimenting with this, and there's two cases that we need to decide how to get the right behavior:
|
When the response has no content-type and verbose is `true` gabbi was not displaying the response body. This is because when no content-type is known, it was assuming a binary content-type. Now it assumes text/plain. This comes with the risk that in some rare cases verbosity might spew data all over the screen if there is a very big or very binary response when no content-type is set. With luck this will encourage servers to send a content-type. An external test, in the form of test-verbosity.sh is added. This was one of several ways of verifying the output. Addresses #282
I think about this way (likely similar to yours view):
This is how I think about it. Pick what you think is useful. |
When the response has no content-type and verbose is `true` gabbi was not displaying the response body. This is because when no content-type is known, it was assuming a binary content-type. Now it assumes text/plain. This comes with the risk that in some rare cases verbosity might spew data all over the screen if there is a very big or very binary response when no content-type is set. With luck this will encourage servers to send a content-type. An external test, in the form of test-verbosity.sh is added. This was one of several ways of verifying the output. Addresses #282
Thanks for the comments. For the time being I've gone with a relatively simple fix in #285 which will be released as version 2.0.4 here in a few minutes. As things move along it might make sense to incorporate some of your other ideas. One thing I don't want to do is automatically decode or detect content-type without a content-type header. Gabbi has always been opinionated about using content-type effectively and encouraging people to write APIs that do so. As gabbi has grown to sometimes be used to test things which the tester has no control over, his has proven a bit more difficult, so it might make sense in the future to change this, but I don't want to make that change without due consideration. |
I have got the following test spec:
which has got data not a proper json on purpose. The response results in 400 instead of 200 code. Verbose is set to all, but it still does not print the response body, although detects non empty content:
The expected behavior:
The text was updated successfully, but these errors were encountered: