Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. let call_request ?interrupt ?(body=`Empty) req =
  2. req >>= fun req ->
  3. (* Connect to the remote side *)
  4. Net.connect_uri ?interrupt (Request.(req.uri))
  5. >>= fun (ic,oc) ->
  6. Request.write (fun writer -> Body.write Request.write_body body writer) req oc
  7. >>= fun () ->
  8. Response.read ic
  9. >>| function
  10. | `Eof -> failwith "Connection closed by remote host"
  11. | `Invalid reason -> failwith reason
  12. | `Ok res ->
  13. (* Build a response pipe for the body *)
  14. let reader = Response.make_body_reader res ic in
  15. let rd = pipe_of_body (fun ic -> Response.read_body_chunk reader) ic oc in
  16. don't_wait_for (
  17. Pipe.closed rd >>= fun () ->
  18. Deferred.all_ignore [Reader.close ic; Writer.close oc]
  19. );
  20. res, `Pipe rd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement