From 371a4f814875ff47c75a76ec57a7a9098f5ab512 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 21 Nov 2020 20:20:50 +0100 Subject: [PATCH] debuginfod: Handle "/" and report unrecognized operations This doesn't change any functionality, but simply shows something a little user friendlier when accessing the server "by hand" (in a browser). Signed-off-by: Mark Wielaard --- debuginfod/ChangeLog | 5 +++++ debuginfod/debuginfod.cxx | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 34e07793a..b3c812856 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2020-11-21 Mark Wielaard + + * debuginfod.cxx (handle_root): New function. + (handler_cb): Handle "/" and report url1 in webapi error. + 2020-11-11 Mark Wielaard * debuginfod-find.c (progressfn): Use clock_gettime to print Progress diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 78e2a4307..61c778b10 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1799,6 +1799,19 @@ handle_metrics (off_t* size) return r; } +static struct MHD_Response* +handle_root (off_t* size) +{ + static string version = "debuginfod (" + string (PACKAGE_NAME) + ") " + + string (PACKAGE_VERSION); + MHD_Response* r = MHD_create_response_from_buffer (version.size (), + (void *) version.c_str (), + MHD_RESPMEM_PERSISTENT); + *size = version.size (); + MHD_add_response_header (r, "Content-Type", "text/plain"); + return r; +} + //////////////////////////////////////////////////////////////////////// @@ -1876,8 +1889,13 @@ handler_cb (void * /*cls*/, inc_metric("http_requests_total", "type", "metrics"); r = handle_metrics(& http_size); } + else if (url1 == "/") + { + inc_metric("http_requests_total", "type", "/"); + r = handle_root(& http_size); + } else - throw reportable_exception("webapi error, unrecognized /operation"); + throw reportable_exception("webapi error, unrecognized '" + url1 + "'"); if (r == 0) throw reportable_exception("internal error, missing response"); -- 2.47.2