-
Notifications
You must be signed in to change notification settings - Fork 2k
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
gcoap: return Method Not Allowed if appropriate #7699
Conversation
e726d62
to
f65728e
Compare
@nmeum, thanks for the PR! I haven't tested yet, but the logic looks sound to me. I recommend macros for the return values, like GCOAP_RESOURCE_FOUND, GCOAP_RESOURCE_NO_PATH, etc. It will make the meaning clearer in _find_resource() and in the caller. You can see similar with the GCOAP_FIND_REQ_... macros. Some of the other _find_... functions return a -1, but that's in the context of a slot number, so not as arbitrary. I'll get back to you as soon as I get a chance to test the code. |
Thanks for the input. Should I add those macros to |
Good thinking -- |
f65728e
to
991f669
Compare
Updated accordingly, let me know if you have any further suggestions. |
IMHO instead of defining/introducing redundant return value you could simply return the appropriate CoAP code, i.e., But it would even be possible to just adapt the current function and use |
I would personally prefer defining an enum type with return values for this kind of use case but that doesn't seem to be the RIOT-way of doing things so I will do whatever @kb2ma prefers. |
991f669
to
0cc6699
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.
ACK. Tests fine for me on native.
I think the alternative from @smlng to use the COAP... codes or 0 works also, and I would be OK with that solution. It does remove the clutter of the macro definitions at the top of gcoap.c
.
On the other hand, I like the present solution because it reads better in the code to use internal resource values separate from external COAP values. It also doesn't add to code size -- it's just labels for numbers.
Code size is impacted by changing the functions return value from But in general, I leave it up to you @kb2ma, as gcoap is your baby 😉 As you already approved I'm fine with that as well. I'll trigger Murdock to make a check ... |
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'd like to make some size comparison before merging this one. I'll report back. But generally nice catch @nmeum
made some checks, code size is only increased marginally, i.e. <20B. And I agree having proper return value might be nice. |
my objections didn't whole, but I'm still undecided whether to approve
typo in my dismissed review: /whole/hold/ |
Happy to talk through the indecision. :-) |
@kb2ma, just for clarification Further, I also saw no functional usage of the I'd also like to get @haukepetersen opinion here. |
Good find on the listener parameter. I added the I agree that since the listener parameter is unused today, we might as well remove it. We can always add it back in if we need it. |
Should this be done in a separate pull request or should I do it in this one? |
Ping? |
please rebase and resolve conflicts. |
0cc6699
to
35fea64
Compare
Done. |
Is there anything left to do to get this merged? |
Let's give this one final rebuild, then I think we can merge as I don't see any objection and this PR was already ACKd ages ago. |
If a resource for a path is defined, but the client sent a request with the wrong method, the server responds with the message code
4.05 Method Not Allowed
by default now.See: https://tools.ietf.org/html/rfc7252#section-5.9.2.6
Regarding coding style it might make sense to define a macro (or an enum) for the return values of
_find_resource
.