Closed mattdowdell closed 4 years ago
@mattdowell thanks for reporting this.
Ideally we should not follow redirects as APIs are defining the supported status codes.
I'm curious to understand if this behaviour is present only on the requests client or is present also in the fido client or bravado-asyncio client.
I'm currently running short on bandwidth so I cannot ensure the publication of a PR in a reasonable time (let's say a week). If you have time to provide a PR addressing this issue it will be great (we do welcome contributions)
Thanks for the quick response @macisamuele.
The fido client calls into twisted at a glance which the docs suggests that it will not follow redirects by default. bravado-asyncio appears to use aiohttp which seems to follow a similar interface as requests and looks to follow redirects by default. All of this is based on navigating unfamiliar code and minimal searching, so take the results with a pinch of salt.
I can look into fixing this - it'd definitely be useful for some API testing my team are doing - if you're able to provide some basic pointers? Some initial searches suggest code around requests_client.py#L338 and client.py#L234 look relevant.
Is there any license agreement to sign as well?
As far as I can tell there are no special agreements to sign.
About the code pointers seems like you have already identified them. A small request would be to add a specific test into bravado.testing.integration_tests to ensure no further regressions on this.
In my API spec, I have an endpoint that returns a 301 redirect. This redirects to another URL on a different server that subsequently returns a 200. However, because bravado is using requests, this redirect never comes back to bravado which gets the 200 (which is not a specified response) and then throws an error.
Relevant section of logs below. Logs without a prefix for where it came from comes from setting
http.client.HTTPConnection.debuglevel = 5
. Comments are inserted for clarity and some addresses are redacted for privacy (as this is on a private network).Initially I wondered if it was worth exposing out redirect configuration to the bravado client, but on reflection I don't think bravado should be doing anything in this area. If the API spec says it returns a 301, bravado should not be doing anything extra that might obscure that. I also wondered that if the responses claim they should return a 30X status then redirects should be implicitly disabled, but that creeps into the territory of being a bit too smart or non-obvious.