-
Notifications
You must be signed in to change notification settings - Fork 214
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
Use the Accept Header to indicate that the response should be JSON #777
base: devel
Are you sure you want to change the base?
Conversation
@twink0r So it looks like this change does not go over well with the CI tests being run - any idea why? |
Looks like we need our parser to recognize that it's json? |
I think the "Content-type" header really has to be removed; "Accept" is technically correct and sufficient. The parser error indicates that Ansible tries to parse the returned data as YAML, which to me seems like a faulty test. |
Yeah I see that the server returned an HTTP error 406
|
So I'm trying to run this on the NetBox demo instance with the following nb_inventory config:
And running the
It fails the exact same way as the CI tests. Remove It would be useful to figure out your configurations which leads to this problem, because so far I have not been able to reproduce it with the demo instance. Summarised: I think we need to work a bit more on this before merging it. |
Even easier to reproduce my experience: Works: Does not work: |
I tested the public NetBox with the same parameters as above and with some additional tests. The public NetBox behaves as it should. Note that when requesting with the 'Accept' header, with 'application/json' as well as with 'application/openapi+json', it returns JSON content. What puzzles me a bit is the different behavior when adding the 'format=openapi' query parameter: setting it provokes a 406 response when also setting the 'Accept' header to 'application/json'. Without the query parameter, it works. So this means that we can change the behavior of the Ansible inventory plugin to use that header. It should work correctly then. See my results here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do this, then we need to change the endpoint URL in the function fetching API docs. As shown in the tests done by @nomaster - https://gist.github.com/nomaster/26487448b1c9f4dbabc0b80bda27a94b
Related Issue
#775
New Behavior
Contrast to Current Behavior
Sends an Accept Header to indicate that's the client only accept JSON as return
...
Discussion: Benefits and Drawbacks
In our case this helps with our caching proxy because this strips all
GET
parameters, e.g. /api/docs/?format=openapi.After the proxy strips the parameters we got a lot of HTML and the nb_inventory crashes (take a look here: #775)
Changes to the Documentation
Proposed Release Note Entry
Use the Accept Header to indicate that the response should be JSON
Double Check
devel
branch.