summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-17 12:52:24 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-17 12:52:33 +0100
commit540b22ce1ca41e66574eb156678a7ff288403951 (patch)
tree58848819a2212459db9002e5eabee3437467821a /src/exchange/taler-exchange-httpd.c
parent153dcdbc61a7abcee03947ff5bef89b21b2e8440 (diff)
downloadexchange-540b22ce1ca41e66574eb156678a7ff288403951.tar.gz
exchange-540b22ce1ca41e66574eb156678a7ff288403951.tar.bz2
exchange-540b22ce1ca41e66574eb156678a7ff288403951.zip
implement rh caching
Diffstat (limited to 'src/exchange/taler-exchange-httpd.c')
-rw-r--r--src/exchange/taler-exchange-httpd.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 1b9333df8..44ac82d60 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -66,6 +66,11 @@ struct ExchangeHttpRequestClosure
* Opaque parsing context.
*/
void *opaque_post_parsing_context;
+
+ /**
+ * Cached request handler for this request (once we have found one).
+ */
+ struct TEH_RequestHandler *rh;
};
@@ -360,7 +365,6 @@ handle_mhd_request (void *cls,
"<html><title>404: not found</title></html>", 0,
&TEH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND
};
- struct TEH_RequestHandler *rh;
struct ExchangeHttpRequestClosure *ecls = *con_cls;
int ret;
void **inner_cls;
@@ -413,18 +417,28 @@ handle_mhd_request (void *cls,
"Handling request (%s) for URL '%s'\n",
method,
url);
-
+ /* on repeated requests, check our cache first */
+ if (NULL != ecls->rh)
+ {
+ ret = ecls->rh->handler (ecls->rh,
+ connection,
+ inner_cls,
+ upload_data,
+ upload_data_size);
+ GNUNET_async_scope_restore (&old_scope);
+ return ret;
+ }
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_HEAD))
method = MHD_HTTP_METHOD_GET; /* treat HEAD as GET here, MHD will do the rest */
for (unsigned int i = 0; NULL != handlers[i].url; i++)
{
- rh = &handlers[i];
+ struct TEH_RequestHandler *rh = &handlers[i];
+
if (0 != strcmp (url, rh->url))
continue;
/* The URL is a match! What we now do depends on the method. */
-
if (0 == strcasecmp (method, MHD_HTTP_METHOD_OPTIONS))
{
GNUNET_async_scope_restore (&old_scope);
@@ -435,8 +449,9 @@ handle_mhd_request (void *cls,
(0 == strcasecmp (method,
rh->method)) )
{
- /* FIXME: consider caching 'rh' in '**connection_cls' to
- avoid repeated lookup! */
+ /* cache to avoid the loop next time */
+ ecls->rh = rh;
+ /* run handler */
ret = rh->handler (rh,
connection,
inner_cls,
@@ -446,6 +461,7 @@ handle_mhd_request (void *cls,
return ret;
}
}
+ /* No handler matches, generate not found */
ret = TEH_MHD_handler_static_response (&h404,
connection,
inner_cls,