merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 2d1e2b3e9992652ab1ff2e7b8a34a511779d04dd
parent 243268314c9c23ed12e320ba9245f856c204401b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  6 Jun 2022 14:31:46 +0200

try to fix #7245 via cache control

Diffstat:
Msrc/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c @@ -35,6 +35,18 @@ */ #define STALE_KYC_TIMEOUT GNUNET_TIME_UNIT_MONTHS +/** + * How long should clients cache a KYC failure response? + */ +#define EXPIRATION_KYC_FAILURE GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 5) + +/** + * How long should clients cache a KYC success response? + */ +#define EXPIRATION_KYC_SUCCESS GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, 1) + /** * Information we keep per /kyc request. @@ -303,8 +315,44 @@ resume_kyc_with_response (struct KycContext *kc, unsigned int response_code, struct MHD_Response *response) { + char dat[128]; + kc->response_code = response_code; kc->response = response; + switch (response_code) + { + case MHD_HTTP_OK: + /* KYC failed, cache briefly */ + TALER_MHD_get_date_string (GNUNET_TIME_relative_to_absolute ( + EXPIRATION_KYC_FAILURE), + dat); + 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, + "max-age=300")); + break; + case MHD_HTTP_NO_CONTENT: + /* KYC passed, cache for a long time! */ + TALER_MHD_get_date_string (GNUNET_TIME_relative_to_absolute ( + EXPIRATION_KYC_SUCCESS), + dat); + 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, + "max-age=3600")); + break; + case MHD_HTTP_BAD_GATEWAY: + case MHD_HTTP_GATEWAY_TIMEOUT: + break; /* no caching */ + } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resuming /kyc handling as exchange interaction is done (%u)\n", response_code);