diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 92b221fdec..991909c4a9 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -484,20 +484,14 @@ void gcoap_register_listener(gcoap_listener_t *listener); /** * @brief Initializes a CoAP request PDU on a buffer. - - * @warning After you use this function, you may not add Options with option - * number less than COAP_OPT_URI_PATH. Otherwise, use the struct-based API - * described with @link net_nanocoap nanocoap @endlink to initialize the - * message. See the implementation of gcoap_req_init() itself as an example. * * @param[out] pdu Request metadata * @param[out] buf Buffer containing the PDU * @param[in] len Length of the buffer - * @param[in] code Request code: GCOAP_[GET|POST|PUT|DELETE] - * @param[in] path Resource path, *must* start with '/' + * @param[in] code Request code, one of COAP_METHOD_XXX + * @param[in] path Resource path, may be NULL * - * @pre @p path not `NULL` - * @pre @p path must start with `/` + * @pre @p path must start with `/` if not NULL * * @return 0 on success * @return < 0 on error diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 79c26dc87b..119a7aaa66 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -645,7 +645,7 @@ void gcoap_register_listener(gcoap_listener_t *listener) int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, const char *path) { - assert((path != NULL) && (path[0] == '/')); + assert((path == NULL) || (path[0] == '/')); pdu->hdr = (coap_hdr_t *)buf; @@ -669,7 +669,9 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, if (hdrlen > 0) { coap_pkt_init(pdu, buf, len - GCOAP_REQ_OPTIONS_BUF, hdrlen); - coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/'); + if (path != NULL) { + coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/'); + } return 0; } else {