This is an automated email from the ASF dual-hosted git repository.

jiahuili430 pushed a commit to branch extract-versions-response
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 77103beb23af1db74688fa6c6ed4de6a489ab7fe
Author: Jiahui Li <[email protected]>
AuthorDate: Thu Jan 23 09:54:25 2025 -0600

    Extract the response of `_versions` endpoint
---
 src/chttpd/src/chttpd_node.erl | 89 ++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 42 deletions(-)

diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 2a8bc6cea..2a67da9e3 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -16,6 +16,7 @@
 -export([
     handle_node_req/1,
     get_stats/0,
+    get_versions/0,
     run_queues/0,
     message_queues/0,
     db_pid_stats/0
@@ -46,48 +47,10 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, 
_Node, <<"_smoosh">>, <<
 handle_node_req(#httpd{path_parts = [_, _Node, <<"_smoosh">>, <<"status">>]} = 
Req) ->
     send_method_not_allowed(Req, "GET");
 % GET /_node/$node/_versions
-handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, 
<<"_versions">>]} = Req) ->
-    IcuVer = couch_ejson_compare:get_icu_version(),
-    UcaVer = couch_ejson_compare:get_uca_version(),
-    ColVer = couch_ejson_compare:get_collator_version(),
-    Hashes = crypto:supports(hashs),
-    EngineName = couch_server:get_js_engine(),
-    JsEngine =
-        case EngineName of
-            <<"spidermonkey">> ->
-                #{
-                    name => EngineName,
-                    version => couch_server:get_spidermonkey_version()
-                };
-            _Other ->
-                #{name => EngineName}
-        end,
-    ClouseauResponse =
-        case clouseau_rpc:version() of
-            {ok, Version} ->
-                #{
-                    clouseau => #{
-                        version => Version
-                    }
-                };
-            _ ->
-                #{}
-        end,
-    BaseResponse = #{
-        erlang => #{
-            version => ?l2b(?COUCHDB_ERLANG_VERSION),
-            supported_hashes => Hashes
-        },
-        collation_driver => #{
-            name => <<"libicu">>,
-            library_version => couch_util:version_to_binary(IcuVer),
-            collation_algorithm_version => 
couch_util:version_to_binary(UcaVer),
-            collator_version => couch_util:version_to_binary(ColVer)
-        },
-        javascript_engine => JsEngine
-    },
-    Response = maps:merge(BaseResponse, ClouseauResponse),
-    send_json(Req, 200, Response);
+handle_node_req(#httpd{method = 'GET', path_parts = [_, Node, 
<<"_versions">>]} = Req) ->
+    Versions = call_node(Node, chttpd_node, get_versions, []),
+    EJSON = couch_stats_httpd:to_ejson(Versions),
+    send_json(Req, EJSON);
 handle_node_req(#httpd{path_parts = [_, _Node, <<"_versions">>]} = Req) ->
     send_method_not_allowed(Req, "GET");
 % GET /_node/$node/_config
@@ -339,6 +302,48 @@ get_stats() ->
         {distribution_events, mem3_distribution:events()}
     ].
 
+get_versions() ->
+    IcuVer = couch_ejson_compare:get_icu_version(),
+    UcaVer = couch_ejson_compare:get_uca_version(),
+    ColVer = couch_ejson_compare:get_collator_version(),
+    Hashes = crypto:supports(hashs),
+    EngineName = couch_server:get_js_engine(),
+    JsEngine =
+        case EngineName of
+            <<"spidermonkey">> ->
+                #{
+                    name => EngineName,
+                    version => couch_server:get_spidermonkey_version()
+                };
+            _Other ->
+                #{name => EngineName}
+        end,
+    ClouseauResponse =
+        case clouseau_rpc:version() of
+            {ok, Version} when is_binary(Version) ->
+                #{
+                    clouseau => #{
+                        version => Version
+                    }
+                };
+            _ ->
+                #{}
+        end,
+    BaseResponse = #{
+        erlang => #{
+            version => ?l2b(?COUCHDB_ERLANG_VERSION),
+            supported_hashes => Hashes
+        },
+        collation_driver => #{
+            name => <<"libicu">>,
+            library_version => couch_util:version_to_binary(IcuVer),
+            collation_algorithm_version => 
couch_util:version_to_binary(UcaVer),
+            collator_version => couch_util:version_to_binary(ColVer)
+        },
+        javascript_engine => JsEngine
+    },
+    maps:merge(BaseResponse, ClouseauResponse).
+
 db_pid_stats_formatted() ->
     {CF, CDU} = db_pid_stats(),
     {format_pid_stats(CF), format_pid_stats(CDU)}.

Reply via email to