challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit f57b7984c77206f74fdd7b7ebb777c8a063c98d9
parent a0dfdffe3b513b0d7791a456c5db528abd66abca
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 21 Apr 2024 10:26:38 +0200

add cache control to /config endpoint

Diffstat:
Msrc/challenger/challenger-httpd_config.c | 53++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/src/challenger/challenger-httpd_config.c b/src/challenger/challenger-httpd_config.c @@ -36,17 +36,52 @@ CH_handler_config (struct CH_HandlerContext *hc, const char *upload_data, size_t *upload_data_size) { + static struct MHD_Response *response; + static struct GNUNET_TIME_Absolute a; + (void) upload_data; (void) upload_data_size; - return TALER_MHD_REPLY_JSON_PACK ( - hc->connection, - MHD_HTTP_OK, - GNUNET_JSON_pack_string ("implementation", - "urn:net:taler:specs:challenger:c-reference"), - GNUNET_JSON_pack_string ("name", - "challenger"), - GNUNET_JSON_pack_string ("version", - "1:0:1")); + if ( (GNUNET_TIME_absolute_is_past (a)) && + (NULL != response) ) + { + MHD_destroy_response (response); + response = NULL; + } + if (NULL == response) + { + struct GNUNET_TIME_Timestamp km; + char dat[128]; + + a = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); + /* Round up to next full day to ensure the expiration + time does not become a fingerprint! */ + a = GNUNET_TIME_absolute_round_down (a, + GNUNET_TIME_UNIT_DAYS); + a = GNUNET_TIME_absolute_add (a, + GNUNET_TIME_UNIT_DAYS); + /* => /config response stays at most 48h in caches! */ + km = GNUNET_TIME_absolute_to_timestamp (a); + TALER_MHD_get_date_string (km.abs_time, + dat); + response = TALER_MHD_MAKE_JSON_PACK ( + GNUNET_JSON_pack_string ("implementation", + "urn:net:taler:specs:challenger:c-reference"), + GNUNET_JSON_pack_string ("name", + "challenger"), + GNUNET_JSON_pack_string ("version", + "1:1:1")); + GNUNET_break (MHD_YES == + MHD_add_response_header (response, + MHD_HTTP_HEADER_EXPIRES, + dat)); + GNUNET_break (MHD_YES == + MHD_add_response_header (response, + MHD_HTTP_HEADER_CACHE_CONTROL, + "public,max-age=21600")); /* 6h */ + } + return MHD_queue_response (hc->connection, + MHD_HTTP_OK, + response); }