@@ -27,41 +27,46 @@ content_types_provided(ReqData, Context) ->
2727 {rabbit_mgmt_util :responder_map (to_json ), ReqData , Context }.
2828
2929resource_exists (ReqData , Context ) ->
30- {case protocol (ReqData ) of
30+ {case protocols (ReqData ) of
3131 none -> false ;
3232 _ -> true
3333 end , ReqData , Context }.
3434
3535to_json (ReqData , Context ) ->
36- Protocol = normalize_protocol (protocol (ReqData )),
37- Listeners = rabbit_networking :active_listeners (),
38- Local = [L || # listener {node = N } = L <- Listeners , N == node ()],
39- ProtoListeners = [L || # listener {protocol = P } = L <- Local , atom_to_list (P ) == Protocol ],
40- case ProtoListeners of
36+ Protocols = string :split (protocols (ReqData ), " ," , all ),
37+ RequestedProtocols = sets :from_list (
38+ [normalize_protocol (P ) || P <- Protocols ],
39+ [{version , 2 }]),
40+ Listeners = rabbit_networking :node_listeners (node ()),
41+ ActiveProtocols = sets :from_list (
42+ [atom_to_list (P ) || # listener {protocol = P } <- Listeners ],
43+ [{version , 2 }]),
44+ MissingProtocols = sets :to_list (sets :subtract (RequestedProtocols , ActiveProtocols )),
45+ case MissingProtocols of
4146 [] ->
42- Msg = <<" No active listener" >>,
43- failure (Msg , Protocol , [P || # listener {protocol = P } <- Local ], ReqData , Context );
47+ Body = #{status => ok ,
48+ protocols => [list_to_binary (P ) || P <- sets :to_list (ActiveProtocols )]},
49+ rabbit_mgmt_util :reply (Body , ReqData , Context );
4450 _ ->
45- Body = #{status => ok ,
46- protocol => list_to_binary (Protocol )},
47- rabbit_mgmt_util :reply (Body , ReqData , Context )
51+ Msg = <<" No active listener" >>,
52+ failure (Msg , MissingProtocols , sets :to_list (ActiveProtocols ), ReqData , Context )
4853 end .
4954
5055failure (Message , Missing , Protocols , ReqData , Context ) ->
5156 Body = #{
5257 status => failed ,
5358 reason => Message ,
54- missing => list_to_binary (Missing ) ,
55- protocols => Protocols
59+ missing => [ list_to_binary (P ) || P <- Missing ] ,
60+ protocols => [ list_to_binary ( P ) || P <- Protocols ]
5661 },
5762 {Response , ReqData1 , Context1 } = rabbit_mgmt_util :reply (Body , ReqData , Context ),
5863 {stop , cowboy_req :reply (503 , #{}, Response , ReqData1 ), Context1 }.
5964
6065is_authorized (ReqData , Context ) ->
6166 rabbit_mgmt_util :is_authorized (ReqData , Context ).
6267
63- protocol (ReqData ) ->
64- rabbit_mgmt_util :id (protocol , ReqData ).
68+ protocols (ReqData ) ->
69+ rabbit_mgmt_util :id (protocols , ReqData ).
6570
6671normalize_protocol (Protocol ) ->
6772 case string :lowercase (binary_to_list (Protocol )) of
0 commit comments