gotthardp/gen_coap

Adding options to responses

erkki opened this issue · 5 comments

erkki commented

I'm having a hard time figuring out how to add options to responses within the resource callbacks. Such as Location-Path/Location-Query in a response to a POST that creates a resource.
I'm looking at adding options as parameters to the callback methods but wondering if I'm missing something.

Hmm. I don't think this is possible with the current implementation.

erkki commented

Thanks for the quick reply :)

erkki commented

For background, this is part of the CoAP spec (and necessary to implement OMA LwM2M):

5.8.2. POST

The POST method requests that the representation enclosed in the
request be processed. The actual function performed by the POST
method is determined by the origin server and dependent on the target
resource. It usually results in a new resource being created or the
target resource being updated.

If a resource has been created on the server, the response returned
by the server SHOULD have a 2.01 (Created) Response Code and SHOULD
include the URI of the new resource in a sequence of one or more
Location-Path and/or Location-Query Options (Section 5.10.7). If the
POST succeeds but does not result in a new resource being created on
the server, the response SHOULD have a 2.04 (Changed) Response Code.
If the POST succeeds and results in the target resource being
deleted, the response SHOULD have a 2.02 (Deleted) Response Code.
POST is neither safe nor idempotent.

I could implement it if you help me with the analysis. I haven't worked with CoAP for few years, so I forgot almost everything.
The question I have is whether each resource shall be associated with a location, or whether the location shall be set in the message only. And the second question is whether the location shall be set automatically based on the request URI or whether the resource handler shall be able to set the location to whatever value it wants.

erkki commented

Sure, I'm just getting familiar with CoAP but I'll try :).

The question I have is whether each resource shall be associated with a location, or whether the location shall be set in the message only.

To me it seems more reasonable that it's in the message only, given that
a) not all resources necessarily associate with a location and
b) Location was just an example of setting options but one should be able to set other options in the response, too (https://tools.ietf.org/html/rfc7252#section-5.4)

And the second question is whether the location shall be set automatically based on the request URI or whether the resource handler shall be able to set the location to whatever value it wants.

Probably the latter, it's still up to the user/server to define semantics.