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

Merge pull request #18471 from miri64/gcoap_forward_proxy/fix/copy-max_age

gcoap_forward_proxy: copy Max-Age from forwarded Valid if it exists
This commit is contained in:
Martine Lenders 2022-09-28 04:36:16 +02:00 committed by GitHub
commit b297b2bd14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -202,8 +202,19 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo,
/* check if we can just send 2.03 Valid instead */
if ((cep->req_etag_len == coap_opt_get_opaque(pdu, COAP_OPT_ETAG, &resp_etag)) &&
(memcmp(cep->req_etag, resp_etag, cep->req_etag_len) == 0)) {
uint32_t max_age;
if (coap_opt_get_uint(pdu, COAP_OPT_MAX_AGE, &max_age) < 0) {
/* use default,
* see https://datatracker.ietf.org/doc/html/rfc7252#section-5.10.5 */
max_age = 60U;
}
gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_VALID);
coap_opt_add_opaque(pdu, COAP_OPT_ETAG, cep->req_etag, cep->req_etag_len);
if (max_age != 60U) {
/* only include Max-Age option if it is not the default value */
coap_opt_add_uint(pdu, COAP_OPT_MAX_AGE, max_age);
}
coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
}
}

View File

@ -1327,7 +1327,7 @@ static ssize_t _cache_check(const uint8_t *buf, size_t len,
uint8_t *start = coap_find_option(&req, COAP_OPT_ETAG);
/* option length must always be <= COAP_ETAG_LENGTH_MAX = 8 < 12, so the length
* is encoded in the first byte, see also RFC 7252, section 3.1 */
*start &= 0x0f;
*start &= 0xf0;
/* first if around here should make sure we are <= 8 < 0xf, so we don't need to
* bitmask resp_etag_len */
*start |= (uint8_t)resp_etag_len;