diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-06-06 14:31:46 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-06-06 14:31:46 +0200 |
commit | 2d1e2b3e9992652ab1ff2e7b8a34a511779d04dd (patch) | |
tree | 71bd010bfe7a722c499f0287905472ee62bd80f7 /src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c | |
parent | 243268314c9c23ed12e320ba9245f856c204401b (diff) |
try to fix #7245 via cache control
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c | 48 |
1 files 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 index e0e2cd39..fbb4f63f 100644 --- 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); |