gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated (b9d0b1aa -> a6b21080)


From: gnunet
Subject: [taler-exchange] branch master updated (b9d0b1aa -> a6b21080)
Date: Tue, 17 May 2022 14:52:59 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository exchange.

    from b9d0b1aa -make batch withdraw requests idempotent
     new 5e06f842 add ETag to /keys response
     new a6a1fa9f keep ETag around
     new a6b21080 -check for ETag in request, generate 304 if applicable

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exchange/taler-exchange-httpd_keys.c | 60 ++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/src/exchange/taler-exchange-httpd_keys.c 
b/src/exchange/taler-exchange-httpd_keys.c
index dea29f7d..0fde1d67 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -243,6 +243,11 @@ struct KeysResponseData
    */
   struct MHD_Response *response_uncompressed;
 
+  /**
+   * ETag for these responses.
+   */
+  char *etag;
+
   /**
    * Cherry-picking timestamp the client must have set for this
    * response to be valid.  0 if this is the "full" response.
@@ -632,6 +637,7 @@ clear_response_cache (struct TEH_KeyStateHandle *ksh)
 
     MHD_destroy_response (krd->response_compressed);
     MHD_destroy_response (krd->response_uncompressed);
+    GNUNET_free (krd->etag);
   }
   GNUNET_array_grow (ksh->krd_array,
                      ksh->krd_array_length,
@@ -1918,6 +1924,7 @@ create_krd (struct TEH_KeyStateHandle *ksh,
     void *keys_jsonz;
     size_t keys_jsonz_size;
     int comp;
+    char etag[sizeof (struct GNUNET_HashCode) * 2];
 
     /* Convert /keys response to UTF8-String */
     keys_json = json_dumps (keys,
@@ -1929,6 +1936,21 @@ create_krd (struct TEH_KeyStateHandle *ksh,
     keys_jsonz = GNUNET_strdup (keys_json);
     keys_jsonz_size = strlen (keys_json);
 
+    /* hash to compute etag */
+    {
+      struct GNUNET_HashCode ehash;
+      char *end;
+
+      GNUNET_CRYPTO_hash (keys_jsonz,
+                          keys_jsonz_size,
+                          &ehash);
+      end = GNUNET_STRINGS_data_to_string (&ehash,
+                                           sizeof (ehash),
+                                           etag,
+                                           sizeof (etag));
+      *end = '\0';
+    }
+
     /* Create uncompressed response */
     krd.response_uncompressed
       = MHD_create_response_from_buffer (keys_jsonz_size,
@@ -1938,6 +1960,10 @@ create_krd (struct TEH_KeyStateHandle *ksh,
     GNUNET_assert (GNUNET_OK ==
                    setup_general_response_headers (ksh,
                                                    krd.response_uncompressed));
+    GNUNET_break (MHD_YES ==
+                  MHD_add_response_header (krd.response_uncompressed,
+                                           MHD_HTTP_HEADER_ETAG,
+                                           etag));
     /* Also compute compressed version of /keys response */
     comp = TALER_MHD_body_compress (&keys_jsonz,
                                     &keys_jsonz_size);
@@ -1956,6 +1982,11 @@ create_krd (struct TEH_KeyStateHandle *ksh,
     GNUNET_assert (GNUNET_OK ==
                    setup_general_response_headers (ksh,
                                                    krd.response_compressed));
+    GNUNET_break (MHD_YES ==
+                  MHD_add_response_header (krd.response_compressed,
+                                           MHD_HTTP_HEADER_ETAG,
+                                           etag));
+    krd.etag = GNUNET_strdup (etag);
   }
   krd.cherry_pick_date = last_cpd;
   GNUNET_array_append (ksh->krd_array,
@@ -2823,7 +2854,11 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
                       const char *const args[])
 {
   struct GNUNET_TIME_Timestamp last_issue_date;
+  const char *etag;
 
+  etag = MHD_lookup_connection_value (rc->connection,
+                                      MHD_HEADER_KIND,
+                                      MHD_HTTP_HEADER_IF_NONE_MATCH);
   (void) args;
   {
     const char *have_cherrypick;
@@ -2904,6 +2939,31 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
          Wait until they are. */
       return suspend_request (rc->connection);
     }
+    if ( (NULL != etag) &&
+         (0 == strcmp (etag,
+                       krd->etag)) )
+    {
+      MHD_RESULT ret;
+      struct MHD_Response *resp;
+
+      resp = MHD_create_response_from_buffer (0,
+                                              NULL,
+                                              MHD_RESPMEM_PERSISTENT);
+      TALER_MHD_add_global_headers (resp);
+      GNUNET_break (GNUNET_OK ==
+                    setup_general_response_headers (ksh,
+                                                    resp));
+      GNUNET_break (MHD_YES ==
+                    MHD_add_response_header (resp,
+                                             MHD_HTTP_HEADER_ETAG,
+                                             krd->etag));
+      ret = MHD_queue_response (rc->connection,
+                                MHD_HTTP_NOT_MODIFIED,
+                                resp);
+      GNUNET_break (MHD_YES == ret);
+      MHD_destroy_response (resp);
+      return ret;
+    }
     return MHD_queue_response (rc->connection,
                                MHD_HTTP_OK,
                                (MHD_YES ==

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]