(* * SPDX-FileCopyrightText: 2026 The Forester Project Contributors * * SPDX-License-Identifier: GPL-3.0-or-later *) let from_form_urlencoded string = if string = "" then [] else string |> Uri.query_of_encoded |> List.map (fun (name, values) -> (name, String.concat "," values)) let get_field k = List.find_map (fun (k', v) -> if k = k' then Some v else None) let parse headers request_body = let status : Http.Status.t = match Http.Header.get headers "Content-Type" with | None -> `Bad_request | Some content_type -> begin match String.split_on_char ';' content_type with | "application/x-www-form-urlencoded" :: _ -> `OK | _ -> `Bad_request end in let form = from_form_urlencoded request_body in (status, form)