From 2d6f52686cee1974334858f9edb57e283e8556bb Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 26 Feb 2016 18:09:36 +0100 Subject: [PATCH] src/net.c: bugfix: remove observer on cancel before invoking resource handler When a client sends a GET request with Observe: 1, it must be removed from the list of observers before the resource handler is called. Otherwise, it will add an Observe option to its response. --- src/net.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/net.c b/src/net.c index 9aadbc22..19762199 100644 --- a/src/net.c +++ b/src/net.c @@ -1444,7 +1444,10 @@ handle_request(coap_context_t *context, coap_queue_t *node) { if (subscription) { coap_touch_observer(context, &node->remote, &token); } - } + } else { + coap_log(LOG_DEBUG, "removed observer\n"); + coap_delete_observer(resource, &node->remote, &token); + } } } @@ -1452,11 +1455,10 @@ handle_request(coap_context_t *context, coap_queue_t *node) { node->pdu, &token, response); if (!no_response(node->pdu, response)) { - if (observe && ((COAP_RESPONSE_CLASS(response->hdr->code) > 2) - || ((observe_action & COAP_OBSERVE_CANCEL) != 0))) { - coap_log(LOG_DEBUG, "removed observer"); - coap_delete_observer(resource, &node->remote, &token); - } + if (observe && (COAP_RESPONSE_CLASS(response->hdr->code) > 2)) { + coap_log(LOG_DEBUG, "removed observer\n"); + coap_delete_observer(resource, &node->remote, &token); + } /* If original request contained a token, and the registered * application handler made no changes to the response, then