-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Send 204 when WebAPI response contains no data #21349
base: master
Are you sure you want to change the base?
Conversation
@@ -373,6 +373,9 @@ void WebApplication::doProcessRequest() | |||
} | |||
} | |||
break; | |||
case QMetaType::UnknownType: |
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 will trigger this case?
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 will trigger this case?
Response w/o data.
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.
Should all responses with no data use 204
? Shouldn't it depend on what was requested?
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.
Should all responses with no data use
204
? Shouldn't it depend on what was requested?
I'm not sure I've understood the gist of your questions correctly...
In current architecture if "action" returns no data (i.e. it doesn't call setResult()
) the data is of type QMetaType::UnknownType
at this point so 204 status is sent in response.
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.
For example, setPreferencesAction()
don't return data but is it expected for the client to receive 204 No Content
in the response? Shouldn't the client expect it to be 200 OK
?
I mean 204
probably should not be sent unconditionally and only some api should use it.
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.
Any request that doesn't result in data being sent back to the client should receive a 204. This page has useful information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status.
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.
I mean
204
probably should not be sent unconditionally and only some api should use it.
What's the point of it then?
What's the point of it then?
IIRC, it means the same as 200 but give the client a hint of that request processing can be optimized.
Shouldn't the client expect it to be
200 OK
?
It should expect the code that is declared by API.
This change is part of a broader push to have the WebAPI send back semantically correct status codes.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204