12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788(**************************************************************************)(* *)(* Copyright 2018-2023 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)typestr_or_star=[`star|`strofstring]typet={typ:str_or_star;subtyp:str_or_star;param:(string*string)option}letparsem=matchString.index_optm'/'with|None->None|Somei->lettyp=String.subm0iinlettyp=iftyp="*"then`starelse`strtypinmatchString.index_from_optm(i+1)';'with|None->letsubtyp=String.subm(i+1)(String.lengthm-i-1)inletsubtyp=ifsubtyp="*"then`starelse`strsubtypinSome{typ;subtyp;param=None}|Somej->letsubtyp=String.subm(i+1)(j-i-1)inletsubtyp=ifsubtyp="*"then`starelse`strsubtypinmatchString.index_from_optm(j+1)'='with|None->Some{typ;subtyp;param=None}|Somek->letkey=String.subm(j+1)(k-j-1)inletv=String.subm(k+1)(String.lengthm-k-1)inSome{typ;subtyp;param=Some(key,v)}letto_stringm=lettyp=matchm.typwith`strs->s|`star->"*"inletsubtyp=matchm.subtypwith`strs->s|`star->"*"inletparam=matchm.paramwithNone->""|Some(k,v)->";"^k^"="^vintyp^"/"^subtyp^paramletallowedlc=ifl=[]thentrueelsematchcwith|None->List.exists(fun{typ;subtyp;_}->typ=`star&&subtyp=`star)l|Somes->matchparseswith|None->false|Some{typ;subtyp;_}->letrecaux=function|[]->false|h::t->((h.typ=`star||h.typ=typ)&&(h.subtyp=`star||h.subtyp=subtyp))||auxtinauxlletjson={typ=`str"application";subtyp=`str"json";param=None}letmultipart={typ=`str"multipart";subtyp=`str"form-data";param=None}leturl_encoded={typ=`str"application";subtyp=`str"x-www-form-urlencoded";param=None}letoctet_stream={typ=`str"application";subtyp=`str"octet-stream";param=None}letcontent_type_of_filefile=letexts=List.rev(String.split_on_char'.'(String.lowercase_ascii(Filename.basenamefile)))inmatchextswith|"js"::_->"text/javascript"|"txt"::_->"text/plain"|"pdf"::_->"application/pdf"|"json"::_->"application/json"|"xml"::_->"application/xml"|"zip"::_->"application/zip"|("html"|"htm")::_->"text/html"|"map"::"css"::_|"css"::_->"text/css"|"png"::_->"image/png"|"jpg"::_|"jpeg"::_|"jfif"::_|"pjpeg"::_|"pjp"::_->"image/jpeg"|"gif"::_->"image/gif"|"svg"::_->"image/svg+xml"|"webp"::_->"image/webp"|"avif"::_->"image/avif"|"apng"::_->"image/apng"|_->"application/octet-stream"