Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lwt/cohttp_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ module type Server = sig
body:string -> unit -> (Cohttp.Response.t * Cohttp_lwt_body.t) Lwt.t

val respond_error :
status:Cohttp.Code.status_code ->
?headers:Header.t ->
?status:Cohttp.Code.status_code ->
body:string -> unit -> (Cohttp.Response.t * Cohttp_lwt_body.t) Lwt.t

val respond_redirect :
Expand Down Expand Up @@ -302,8 +303,8 @@ module Make_server(IO:Cohttp.S.IO with type 'a t = 'a Lwt.t)
let body = Cohttp_lwt_body.of_string body in
return (res,body)

let respond_error ~status ~body () =
respond_string ~status ~body:("Error: "^body) ()
let respond_error ?headers ?(status=`Internal_server_error) ~body () =
respond_string ?headers ~status ~body:("Error: "^body) ()

let respond_redirect ?headers ~uri () =
let headers =
Expand Down Expand Up @@ -367,7 +368,7 @@ module Make_server(IO:Cohttp.S.IO with type 'a t = 'a Lwt.t)
try_lwt
spec.callback (io_id,conn_id) req body
with exn ->
respond_error ~status:`Internal_server_error ~body:(Printexc.to_string exn) ()
respond_error ~body:(Printexc.to_string exn) ()
finally Cohttp_lwt_body.drain_body body
) req_stream in
(* Clean up resources when the response stream terminates and call
Expand Down
3 changes: 2 additions & 1 deletion lwt/cohttp_lwt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ module type Server = sig
body:string -> unit -> (Response.t * Cohttp_lwt_body.t) Lwt.t

val respond_error :
status:Cohttp.Code.status_code ->
?headers:Header.t ->
?status:Cohttp.Code.status_code ->
body:string -> unit -> (Response.t * Cohttp_lwt_body.t) Lwt.t

val respond_redirect :
Expand Down