diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-26 10:32:11 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-26 16:25:25 +0200 |
commit | 0baebf01516b68f07fe69038828f503a517b0d34 (patch) | |
tree | 1b99a72da55776b57cf2b0f585b0011ab0b4ad2c /portal/ws | |
parent | 2402c5c9d027d13f864121bde1d8948c0d5efddc (diff) |
refactor(portal_ws): stanza_open to header
Diffstat (limited to 'portal/ws')
-rw-r--r-- | portal/ws/portal.ml | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/portal/ws/portal.ml b/portal/ws/portal.ml index 620d70e..b2a3119 100644 --- a/portal/ws/portal.ml +++ b/portal/ws/portal.ml @@ -16,7 +16,7 @@ let well_known_of (domain : string) = "https://" ^ domain ^ "/.well-known/host-m (** [open_stanza domain] is an <open /> stanza for [domain]. If [from] is specified, the <open /> stanza has the from parameter. *) -let stanza_open ?from domain : (signal, sync) stream = +let header ?from domain (stream, push) = let stanza = let attributes = let open Option in @@ -29,7 +29,22 @@ let stanza_open ?from domain : (signal, sync) stream = ((xmlns, "open"), attributes); `End_element] - in stanza |> of_list + and error = Lwt.fail_with "TODO" + in push (Some (of_list stanza)); + let* stanza_open = Markup_lwt.next stream in + let some id = + let* close = Markup_lwt.next stream in + match close with + | Some `End_element -> Lwt.return id + | _ -> error + in + match stanza_open with + | Some `Start_element ((ns, "open"), attributes) when ns = xmlns -> + List.find_map + (fun ((_, name), value) -> if name = "id" then Some value else None) + attributes + |> Option.fold ~none:error ~some + | _ -> error let stanza_close = {|<close xmlns="|} ^ xmlns ^ {|" />|} |> string |> parse_xml |> signals |