Skip to content

Commit

Permalink
Merge pull request #324 from samoht/master
Browse files Browse the repository at this point in the history
Fix unwanted REST API breakage
  • Loading branch information
samoht committed Oct 14, 2015
2 parents 4d2859f + 10a8fb4 commit fd05767
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
matrix:
- OCAML_VERSION=4.01
- OCAML_VERSION=4.02
- OCAML_VERSIOM=4.02 DEPOTS=cohttp
- OCAML_VERSIOM=4.01 DEPOTS=git
- OCAML_VERSIOM=4.01 DEPOTS="cohttp git"
- OCAML_VERSION=4.02 DEPOTS=cohttp
- OCAML_VERSION=4.01 DEPOTS=git
- OCAML_VERSION=4.01 DEPOTS="cohttp git"
- OCAML_VERSION=4.01 DEPOTS=mirage-git
22 changes: 12 additions & 10 deletions lib/http/irmin_http_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,24 @@ module Request = struct
let write task body = Tc.write_string (module T) (task, body)
let read buf = Tc.read_string (module T) buf

let to_string ct (task, body) = match ct, body with
let to_string ct (task, body) =
let with_task arr = match task with
| None -> `O arr
| Some t -> `O (("task", Irmin.Task.to_json t) :: arr)
in
match ct, body with
| _ , Some (Raw r) -> write task (Some r)
| `Raw, None -> write task None
| _ , Some (Json j) ->
let task = TaskOpt.to_json task in
let json = `O [ ("task", task); ("params", j) ] in
Ezjsonm.to_string json
| `Json, None ->
let task = TaskOpt.to_json task in
let json = `O [ ("task", task) ] in
Ezjsonm.to_string json
| _ , Some (Json j) -> Ezjsonm.to_string (with_task ["params", j])
| `Json, None -> Ezjsonm.to_string (with_task [])

let contents_of_json body =
try match Ezjsonm.from_string body with
| `O l ->
let task = TaskOpt.of_json (List.assoc "task" l) in
let task =
try Some (Irmin.Task.of_json (List.assoc "task" l))
with Not_found -> None
in
let params =
try Some (Json (List.assoc "params" l)) with Not_found -> None
in
Expand Down

0 comments on commit fd05767

Please sign in to comment.