forked from mirage/ocaml-rpc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mirage#10 from djs55/unix-subpackage
Make more mirage and javascript friendly
- Loading branch information
Showing
4 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
open Lwt | |||
open Js | |||
|
|||
let do_rpc ~url call = | |||
let method_ = "POST" in | |||
let content_type = "text/xml" in | |||
let contents = Xmlrpc.string_of_call call in | |||
let (res, w) = Lwt.task () in | |||
let req = XmlHttpRequest.create () in | |||
|
|||
req##_open (Js.string method_, Js.string url, Js._true); | |||
req##setRequestHeader (Js.string "Content-type", Js.string content_type); | |||
|
|||
(* List.iter (fun (n, v) -> req##setRequestHeader (Js.string n, Js.string v)) headers;*) | |||
|
|||
req##onreadystatechange <- Js.wrap_callback | |||
(fun _ -> | |||
(match req##readyState with | |||
| XmlHttpRequest.DONE -> | |||
Lwt.wakeup w (Xmlrpc.response_of_string (Js.to_string req##responseText)) | |||
(* | |||
{XmlHttpRequest.url = url; | |||
code = req##status; | |||
content = Js.to_string req##responseText; | |||
content_xml = | |||
(fun () -> | |||
match Js.Opt.to_option (req##responseXML) with | |||
| None -> None | |||
| Some doc -> | |||
if (Js.some doc##documentElement) == Js.null | |||
then None | |||
else Some doc); | |||
headers = fun _ -> None; | |||
} | |||
*) | |||
| _ -> ())); | |||
|
|||
req##send (Js.some (Js.string contents)); | |||
|
|||
Lwt.on_cancel res (fun () -> req##abort ()) ; | |||
res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
(* | |||
* Copyright (C) 2012 Citrix Systems Inc. | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU Lesser General Public License as published | |||
* by the Free Software Foundation; version 2.1 only. with the special | |||
* exception on linking described in file LICENSE. | |||
* | |||
* 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 Lesser General Public License for more details. | |||
*) | |||
|
|||
val do_rpc : url:string -> Rpc.call -> Rpc.response Lwt.t |