-
Notifications
You must be signed in to change notification settings - Fork 352
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
Respect Accept header when processing requests #333
Conversation
0fb4864
to
97f6608
Compare
354c49c
to
7487ab8
Compare
Given the requirement changes, if we can figure out WHEN exactly send a 406, this could close #288 as well. Right now, in case the content is not found, we're returning an empty body with the requested status code. Maybe we should return a 406? |
3dfd882
to
fa254ba
Compare
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.
What happens if this is the produces for an operation?
['application/xml', 'text/plain']
And the accepts header is:
'image/jpeg;q=0.8, application/xml;q=0.3, text/plain;q=0.2'
Prism should try to mock image/jpeg
, but it isn't defined in produces. So we should then try to find application/xml
and because it is defined in produces we should mock it. Is that how it works?
So the "returning an empty body" thing is when we have confirmed that a code should be sent back and we've just failed to find an example. We want to add a layer in, before the example/empty stuff even comes into play, which is "are they accepting for a valid content type. If they ask for a content type the spec doesnt support according to accepts package, errors. If they ask for a content type that is supported but doesnt have any example or schema, then empty body. Does that make sense? |
@pytlesk4 Good point on the multiple http headers — I'll write a test right now and fix it if necessary. |
@philsturgeon d120bad implements the requested behaviour. I'd suggest you to pull out the branch and check it out really quickly. |
Really close!
It should be returning a problems JSON and that message is looking a bit funky. |
@philsturgeon Try it again, it should be ok now.
|
Co-Authored-By: Phil Sturgeon <me@philsturgeon.uk>
@philsturgeon Harness for 406 response added. |
test-harness/gold-master-files/__path____user_username___method___GET__.json
Show resolved
Hide resolved
amazing! |
*/*
(and this is something we do not to support yet)fastify-accept-serialiser
to use the normalstringify
not only onapplication/json
but to anything that can be serialised as JSON anywayCloses #332
Closes #288