@@ -171,18 +171,30 @@ module type HTTP = sig
171171 (string * string ) list -> [> `Error of string | `Ok of string ] IO .t
172172end
173173
174- let show_result ?(verbose =false ) = function
174+ let show_result' ?(verbose =false ) = function
175175| Error code -> sprintf " (%d) %s" (Curl. errno code) (Curl. strerror code)
176176| Ok (n , content ) -> sprintf " http %d%s" n (if verbose then " : " ^ content else " " )
177177
178- let simple_result ?verbose (_ ,r ) =
178+ let show_result ?verbose r =
179+ show_result' ?verbose @@ match r with
180+ | `Ok x -> Ok x
181+ | `Error e -> Error e
182+
183+ let simple_result' ?verbose (_ ,r ) =
179184 match r with
180185 | Ok (n ,s ) when n / 100 = 2 -> `Ok s
181- | r -> `Error (show_result ?verbose r)
186+ | r -> `Error (show_result' ?verbose r)
187+
188+ let simple_result ?verbose r =
189+ let res = match r with
190+ | `Ok s -> Ok s
191+ | `Error e -> Error e
192+ in
193+ simple_result' ?verbose (() , res)
182194
183195let http_result ?verbose (h ,r ) =
184196 match r with
185- | Error _ -> `Error (show_result ?verbose r)
197+ | Error _ -> `Error (show_result' ?verbose r)
186198 | Ok (n ,(s :string )) ->
187199 match n/ 100 with
188200 | 2 -> `Ok (n,s)
@@ -433,7 +445,7 @@ module Http (IO : IO_TYPE) (Curl_IO : CURL with type 'a t = 'a IO.t) : HTTP with
433445 (* could be [~result:snd], but need to keep compatibility *)
434446 let http_request' = http_request_k ~result: (function (_ ,Ok x ) -> `Ok x | (_ ,Error e ) -> `Error e)
435447
436- let http_request ?verbose = http_request_k ?verbose ~result: (simple_result ?verbose)
448+ let http_request ?verbose = http_request_k ?verbose ~result: (simple_result' ?verbose)
437449
438450 let http_request_exn ?verbose ?ua ?timeout ?setup ?timer ?max_size ?http_1_0 ?headers ?body (action :http_action ) url =
439451 http_request ?verbose ?ua ?timeout ?setup ?timer ?max_size ?http_1_0 ?headers ?body action url
0 commit comments