diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index d0c86e863d2c..3605d9b12aa0 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -499,6 +499,18 @@ static inline unsigned coap_get_code_raw(const coap_pkt_t *pkt) return (unsigned)pkt->hdr->code; } +/** + * @brief Get a request's method type + * + * @param[in] pkt CoAP request packet + * + * @returns request method type + */ +static inline coap_method_t coap_get_method(const coap_pkt_t *pkt) +{ + return pkt->hdr->code; +} + /** * @brief Get the message ID of the given CoAP packet * diff --git a/sys/net/application_layer/nanocoap/fileserver.c b/sys/net/application_layer/nanocoap/fileserver.c index 2be41bf7983b..50ec708d61fa 100644 --- a/sys/net/application_layer/nanocoap/fileserver.c +++ b/sys/net/application_layer/nanocoap/fileserver.c @@ -434,7 +434,7 @@ static ssize_t _delete_file(coap_pkt_t *pdu, uint8_t *buf, size_t len, static ssize_t nanocoap_fileserver_file_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, struct requestdata *request) { - switch (coap_get_code_raw(pdu)) { + switch (coap_get_method(pdu)) { case COAP_METHOD_GET: return _get_file(pdu, buf, len, request); #if IS_USED(MODULE_NANOCOAP_FILESERVER_PUT) @@ -568,7 +568,7 @@ static ssize_t nanocoap_fileserver_directory_handler(coap_pkt_t *pdu, uint8_t *b struct requestdata *request, const char *root, const char* resource_dir) { - switch (coap_get_code_raw(pdu)) { + switch (coap_get_method(pdu)) { case COAP_METHOD_GET: return _get_directory(pdu, buf, len, request, root, resource_dir); #if IS_USED(MODULE_NANOCOAP_FILESERVER_PUT)