diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-02-09 23:51:10 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-02-09 23:51:10 +0100 |
commit | 935f9b571d2b47f10a552980feecee76ebcc3593 (patch) | |
tree | 4050ef938097810a709be48b6051ed0009b5ced5 | |
parent | 34c57d80369fac7168313ec1e68ecf74f2519fb9 (diff) | |
download | merchant-935f9b571d2b47f10a552980feecee76ebcc3593.tar.gz merchant-935f9b571d2b47f10a552980feecee76ebcc3593.tar.bz2 merchant-935f9b571d2b47f10a552980feecee76ebcc3593.zip |
fix redirection issue to preserve query parameters
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 39 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 5 |
2 files changed, 36 insertions, 8 deletions
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; } @@ -736,6 +737,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, * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback @@ -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, diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index 7ccf0575..1e5e955d 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -589,6 +589,11 @@ struct TMH_HandlerContext const char *url; /** + * Copy of our original full URL with query parameters. + */ + char *full_url; + + /** * Client-provided authentication token for this * request, can be NULL. * |