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 <m...@klomp.org> --- debuginfod/ChangeLog | 5 +++++ debuginfod/debuginfod.cxx | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index d4face2d..e2ae4785 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2020-11-21 Mark Wielaard <m...@klomp.org> + + * debuginfod.cxx (handle_root): New function. + (handler_cb): Handle "/" and report url1 in webapi error. + 2020-11-11 Mark Wielaard <m...@klomp.org> * debuginfod-find.c (progressfn): Use clock_gettime to print Progress diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index d2a434ee..c112e8a0 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1784,6 +1784,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; +} + //////////////////////////////////////////////////////////////////////// @@ -1859,8 +1872,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.18.4