mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
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.
This commit is contained in:
1 parent
52b98489b5
commit
2d6f52686c
1 file changed
+8
-6
@@ -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
|
||||
|
||||
Reference in new issue
Block a user