From 935f9b571d2b47f10a552980feecee76ebcc3593 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 9 Feb 2024 23:51:10 +0100 Subject: fix redirection issue to preserve query parameters --- src/backend/taler-merchant-httpd.c | 39 ++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'src/backend/taler-merchant-httpd.c') diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 42cf08ee..829daf55 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2022 Taler Systems SA + (C) 2014-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -497,6 +497,7 @@ handle_mhd_completion_callback (void *cls, json_decref (hc->request_body); if (NULL != hc->instance) TMH_instance_decref (hc->instance); + GNUNET_free (hc->full_url); GNUNET_free (hc); *con_cls = NULL; } @@ -735,6 +736,29 @@ prefix_match (const struct TMH_RequestHandler *rh, } +/** + * Function called first by MHD with the full URL. + * + * @param cls NULL + * @param full_url the full URL + * @param con MHD connection object + * @return our handler context + */ +static void * +full_url_track_callback (void *cls, + const char *full_url, + struct MHD_Connection *con) +{ + struct TMH_HandlerContext *hc; + + hc = GNUNET_new (struct TMH_HandlerContext); + GNUNET_async_scope_fresh (&hc->async_scope_id); + GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id); + hc->full_url = GNUNET_strdup (full_url); + return hc; +} + + /** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, @@ -770,7 +794,8 @@ prefix_match (const struct TMH_RequestHandler *rh, * If necessary, this state can be cleaned up in the * global #MHD_RequestCompletedCallback (which * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). - * Initially, `*con_cls` will be NULL. + * Initially, `*con_cls` will be set up by the + * full_url_track_callback(). * @return #MHD_YES if the connection was handled successfully, * #MHD_NO if the socket must be closed due to a serious * error while handling the request @@ -1413,7 +1438,7 @@ url_handler (void *cls, (void) cls; (void) version; - if (NULL != hc) + if (NULL != hc->url) { /* MHD calls us again for a request, for first call see 'else' case below */ @@ -1461,10 +1486,6 @@ url_handler (void *cls, connection, hc); } - hc = GNUNET_new (struct TMH_HandlerContext); - *con_cls = hc; - GNUNET_async_scope_fresh (&hc->async_scope_id); - GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id); hc->url = url; { const char *correlation_id; @@ -1509,7 +1530,7 @@ url_handler (void *cls, strlen (instance_prefix))) { /* url starts with "/instances/" */ - const char *istart = url + strlen (instance_prefix); + const char *istart = hc->full_url + strlen (instance_prefix); const char *slash = strchr (istart, '/'); char *instance_id; @@ -2303,6 +2324,8 @@ run (void *cls, NULL, NULL, &url_handler, NULL, MHD_OPTION_LISTEN_SOCKET, fh, + MHD_OPTION_URI_LOG_CALLBACK, + &full_url_track_callback, NULL, MHD_OPTION_NOTIFY_COMPLETED, &handle_mhd_completion_callback, NULL, MHD_OPTION_CONNECTION_TIMEOUT, -- cgit v1.2.3