Something went wrong. Try again.
ocaml
Something went wrong. Try again.
776 B · 26 lines
OCaml
at pp-ast
123456789101112131415161718192021222324252627(* * 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)