diff --git a/sys/net/application_layer/gcoap/forward_proxy.c b/sys/net/application_layer/gcoap/forward_proxy.c index c2bf37ef87de..afe811f6c6ec 100644 --- a/sys/net/application_layer/gcoap/forward_proxy.c +++ b/sys/net/application_layer/gcoap/forward_proxy.c @@ -276,6 +276,9 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo, /* No harm done in removing a timer that's not active */ ztimer_remove(ZTIMER_MSEC, &cep->empty_ack_timer); buf_len = coap_get_total_len(pdu); + assert(memo->state == GCOAP_MEMO_RESP || + memo->state == GCOAP_MEMO_RESP_TRUNC || + memo->state == GCOAP_MEMO_TIMEOUT); if (memo->state == GCOAP_MEMO_RESP) { uint8_t req_etag_len = _cep_get_req_etag_len(cep); @@ -304,6 +307,7 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo, } #endif } + _set_response_type(pdu, _cep_get_response_type(cep)); /* we do not need to check if valid came from upstream as this is already automatically * converted by the client-side to the cached response */ /* else forward the response packet as-is to the client */ @@ -315,8 +319,13 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo, assert(buf_len >= (sizeof(*pdu->hdr) + 4U)); gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_INTERNAL_SERVER_ERROR); coap_opt_finish(pdu, COAP_OPT_FINISH_NONE); + _set_response_type(pdu, _cep_get_response_type(cep)); + } + else if (memo->state == GCOAP_MEMO_TIMEOUT) { + /* send RST */ + gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_EMPTY); + coap_opt_finish(pdu, COAP_OPT_FINISH_NONE); } - _set_response_type(pdu, _cep_get_response_type(cep)); /* don't use buf_len here, in case the above `gcoap_resp_init`s changed `pdu` */ _dispatch_msg(pdu->hdr, coap_get_total_len(pdu), &cep->ep, &cep->proxy_ep); _free_client_ep(cep); diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 2e9d4e7e460a..86272c7622a9 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1045,7 +1045,9 @@ static void _expire_request(gcoap_request_memo_t *memo) /* Pass response to handler */ if (memo->resp_handler) { coap_pkt_t req; - + memset(&req, 0, sizeof(req)); + /* 0 means there is an observe option value */ + coap_clear_observe(&req); req.hdr = gcoap_request_memo_get_hdr(memo); memo->resp_handler(memo, &req, NULL); }