1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586(*********************************************************************************)(* OCaml-RDF *)(* *)(* Copyright (C) 2012-2024 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public License *)(* along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)openRdf.Sparql_protocol(* Getting result *)letresult_of_responsef(header,body)=letstatus=Cohttp.Code.code_of_status(Cohttp.Response.statusheader)inletcontent_type=matchCohttp.Header.get(Cohttp.Response.headersheader)"Content-Type"withNone->""|Somes->sinlet%lwtbody_string=Cohttp_lwt.Body.to_stringbodyinmatchstatuswith|400->Lwt.return(Error(Malformed_querybody_string))|500->Lwt.return(Error(Query_request_refusedbody_string))|nwhenn>=200&&n<300->Lwt.return(f~content_typebody_string)|n->Lwt.return(Error(Error_other("HTTP return code: "^(string_of_intn))));;(* Other tools *)letbase_headers?accept()=letheaders=matchacceptwithNone->Cohttp.Header.init()|Somes->Cohttp.Header.init_with"accept"sinCohttp.Header.addheaders"user-agent"("ocaml-rdf/"^(Rdf.Config.version()))moduleP=structtype'at='aLwt.tletgeturi?acceptf=letheaders=base_headers?accept()inlet%lwtres=Cohttp_lwt_unix.Client.get~headersuriinresult_of_responsefresletpost(uri:Uri.t)?accept~content_type~content(f:content_type:string->string->out_message)=letheaders=base_headers?accept()inletheaders=Cohttp.Header.addheaders"Content-Type"content_typeinletheaders=Cohttp.Header.addheaders"Content-Length"(string_of_int(String.lengthcontent))inletbody=letstream=Cohttp_lwt.Body.create_stream(funs->Lwt.return(Cohttp.Transfer.Final_chunks))contentinCohttp_lwt.Body.of_streamstreaminlet%lwtres=Cohttp_lwt_unix.Client.post~body~chunked:false~headersuriinresult_of_responsefresendmoduleM=Rdf.Sparql_http.Make(P)includeM