diff options
author | Clombrong <clombrong@egregore.fun> | 2025-04-24 18:30:36 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-04-24 18:30:36 +0200 |
commit | 94dc992612350121a3b51614f6e3e382d8795ae2 (patch) | |
tree | f8da9e9d72aae9ab8086313c099a47c4679bedd4 | |
parent | 5ee2ada0af0400c6593fbf7634dd8370f2d986a2 (diff) |
fix: make parse_xrd accept XRD with whitespace
-rw-r--r-- | portal/lib/portal_ws.ml | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/portal/lib/portal_ws.ml b/portal/lib/portal_ws.ml index 366f524..5377ed9 100644 --- a/portal/lib/portal_ws.ml +++ b/portal/lib/portal_ws.ml @@ -18,21 +18,21 @@ let ws_endpoint (domain : string) = let+ host_meta = Js_of_ocaml_lwt.XmlHttpRequest.perform_raw_url (well_known_of domain) in let i = Xmlm.make_input (`String (0, host_meta.content)) (* This ugly function extracts the href element from a Link tag's attributes if it's a websocket. *) - and link_websocket attrs = - match attrs with + and link_websocket = function + | ((_, "rel"), "urn:xmpp:alt-connections:websocket") :: ((_, "href"), href) :: _ | ((_, "href"), href) :: ((_, "rel"), "urn:xmpp:alt-connections:websocket") :: _ -> Some href - | ((_, "rel"), "urn:xmpp:alt-connections:websocket") :: ((_, "href"), href) :: _ -> Some href | _ -> None - in let parse_tree = (* Parse a single XRD tree. *) + in let parse_xrd = (* Parse a single XRD tree. *) Xmlm.input_tree ~el:(fun tag children -> match tag with | ((_, "Link"), attributes) -> link_websocket attributes | ((_, "XRD"), _) -> List.find_map (fun x -> x) children | _ -> None) - ~data:(fun x -> Some x) - in ignore (Xmlm.input i); (* DTD *) - match parse_tree i with + (* The XRD tree doesn't hold any relevant XML data. *) + ~data:(fun _ -> None) + in ignore (Xmlm.input i); (* DTD stuff *) + match parse_xrd i with | Some uri -> uri | None -> failwith (domain ^ "doesn't advertise a WebSocket endpoint via Web-host Metadata.") |