]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: Handle "/" and report unrecognized operations
authorMark Wielaard <mark@klomp.org>
Sat, 21 Nov 2020 19:20:50 +0000 (20:20 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 21 Nov 2020 23:09:33 +0000 (00:09 +0100)
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 <mark@klomp.org>
debuginfod/ChangeLog
debuginfod/debuginfod.cxx

index 34e07793adf10940054ef87227b9767349ea403d..b3c812856b22659e53d8dd4a8a05bc3fa779ec73 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-21  Mark Wielaard  <mark@klomp.org>
+
+       * debuginfod.cxx (handle_root): New function.
+       (handler_cb): Handle "/" and report url1 in webapi error.
+
 2020-11-11  Mark Wielaard  <mark@klomp.org>
 
        * debuginfod-find.c (progressfn): Use clock_gettime to print Progress
index 78e2a4307f81b167852a4279fd94fbe5a1eb6ffd..61c778b10893435eb84d1bc51862f29929016414 100644 (file)
@@ -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");