summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c48
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);