commit 0730b08d6bb0381423cf4015c689e33cf57cffbd
parent 2e05624e11631d3fe2236f51adb7f085183bd187
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 31 May 2026 14:29:25 +0200
fix #9424 for challenger-httpd: properly return set of allowed methods with 405 response
Diffstat:
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c
@@ -289,13 +289,45 @@ url_handler (void *cls,
{
if (found)
{
+ char allow[128] = "OPTIONS";
+ size_t aoff = strlen ("OPTIONS");
+ struct MHD_Response *resp;
+ enum MHD_Result ret;
+
GNUNET_break_op (0);
- /* FIXME-#9424: return which methods are allowed ... */
- return TALER_MHD_reply_static (hc->connection,
- MHD_HTTP_METHOD_NOT_ALLOWED,
- "text/plain",
- NULL,
- 0);
+ /* Build Allow header: OPTIONS is always supported (handled above),
+ plus every method registered for this URL. */
+ for (unsigned int j = 0; NULL != handlers[j].url; j++)
+ {
+ const struct CH_RequestHandler *rh2 = &handlers[j];
+
+ if ( (0 != strcmp (url, rh2->url)) &&
+ ! ( (0 == strncmp (url, rh2->url, strlen (rh2->url))) &&
+ (1 < strlen (rh2->url)) &&
+ ('/' == rh2->url[strlen (rh2->url) - 1]) ) )
+ continue;
+ GNUNET_assert (aoff + strlen (rh2->method) + 3 < sizeof (allow));
+ memcpy (&allow[aoff], ", ", 2);
+ aoff += 2;
+ memcpy (&allow[aoff], rh2->method, strlen (rh2->method));
+ aoff += strlen (rh2->method);
+ allow[aoff] = '\0';
+ }
+
+ resp = MHD_create_response_from_buffer (0,
+ NULL,
+ MHD_RESPMEM_PERSISTENT);
+ TALER_MHD_add_global_headers (resp,
+ false);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_ALLOW,
+ allow));
+ ret = MHD_queue_response (hc->connection,
+ MHD_HTTP_METHOD_NOT_ALLOWED,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
}
GNUNET_break_op (0);
return TALER_MHD_reply_static (hc->connection,