body_size: Support configuration of max supported body size for RFC7959

Function coap_context_set_max_body_size() added.

For servers, if body size is too large, a 4.13 response is generated.

For clients, if the body size is too large, the server gets a RST and
no date is passed to the application.  A new event COAP_EVENT_BLOCK_ISSUE
is generated.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2026-01-29 09:53:52 +00:00
1 parent 6c0be0c898
commit 07c7a7aa57
13 files changed
+150 -9

No files matched your search

+2
View File
@@ -75,6 +75,8 @@ typedef enum {
COAP_EVENT_PARTIAL_BLOCK = 0x3001,
/** Triggered when not all of a large body has been transmitted */
COAP_EVENT_XMIT_BLOCK_FAIL = 0x3002,
/** Triggered when a block transfer could not be handled */
COAP_EVENT_BLOCK_ISSUE = 0x3003,
/*
* Server session events
+9
View File
@@ -328,6 +328,15 @@ void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds);
*/
int coap_context_set_cid_tuple_change(coap_context_t *context, uint8_t every);
/**
* Set the maximum supported body size.
*
* @param context The coap_context_t object.
* @param max_body_size The maximum supported body size. 0 indicates unlimited.
*/
void coap_context_set_max_body_size(coap_context_t *context,
uint32_t max_body_size);
/**
* Set the maximum token size (RFC8974).
*
+3 -2
View File
@@ -224,8 +224,9 @@ struct coap_context_t {
#endif /* COAP_CLIENT_SUPPORT */
uint32_t block_mode; /**< Zero or more COAP_BLOCK_ or'd options */
coap_resource_dynamic_create_t dyn_create_handler; /**< Dynamc resource create handler */
uint32_t dynamic_cur; /* Current number of dynamic resources */
uint32_t dynamic_max; /* Max number of dynamic resources or 0 is unlimited */
uint32_t dynamic_cur; /**< Current number of dynamic resources */
uint32_t dynamic_max; /**< Max number of dynamic resources or 0 is unlimited */
uint32_t max_body_size; /**< Max supported body size or 0 is unlimited */
};
/**