1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #20915 from fabian18/pr/gcoap_forward_proxy_timeout

gcoap/forward_proxy: handle timeout case
This commit is contained in:
benpicco 2024-10-23 21:58:57 +00:00 committed by GitHub
commit 87c825dd82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -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);

View File

@ -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);
}