lwt request_handler
This commit is contained in:
parent
bd44c46fca
commit
6318be5aad
3 changed files with 36 additions and 19 deletions
|
|
@ -16,26 +16,43 @@ let http_1_1_request_handler reqd =
|
|||
let request = H1.Reqd.request reqd in
|
||||
Log.debug (fun m ->
|
||||
m "(HTTP/1.1) request-handler: %S" request.H1.Request.target);
|
||||
let Mte.{ status; headers; content } =
|
||||
Mte.request_handler (request_from_h1 ~scheme:"http" request)
|
||||
in
|
||||
let status =
|
||||
match status with
|
||||
| #H1.Status.t as status -> status
|
||||
| _ -> Fmt.failwith "H2 status response on a H1 request"
|
||||
in
|
||||
let headers = H1.Headers.of_list (Headers.to_list headers) in
|
||||
let response = H1.Response.create ~headers status in
|
||||
H1.Reqd.respond_with_string reqd response content
|
||||
Lwt.async @@ fun () ->
|
||||
Lwt.catch
|
||||
(fun () ->
|
||||
let open Syntax in
|
||||
let+ Mte.{ status; headers; content } =
|
||||
Mte.request_handler (request_from_h1 ~scheme:"http" request)
|
||||
in
|
||||
let status =
|
||||
match status with
|
||||
| #H1.Status.t as status -> status
|
||||
| _ -> Fmt.failwith "H2 status response on a H1 request"
|
||||
in
|
||||
let headers = H1.Headers.of_list (Headers.to_list headers) in
|
||||
let response = H1.Response.create ~headers status in
|
||||
H1.Reqd.respond_with_string reqd response content;
|
||||
())
|
||||
(fun exn ->
|
||||
(* note: not sure what this does exactly, this is what is done in Dream *)
|
||||
H1.Reqd.report_exn reqd exn;
|
||||
Lwt.return_unit)
|
||||
|
||||
let http_2_0_request_handler reqd =
|
||||
let request = H2.Reqd.request reqd in
|
||||
Log.debug (fun m -> m "(H2) request-handler: %S" request.H2.Request.target);
|
||||
let Mte.{ status; headers; content } =
|
||||
Mte.request_handler (request_from_h2 request)
|
||||
in
|
||||
let response = H2.Response.create ~headers status in
|
||||
H2.Reqd.respond_with_string reqd response content
|
||||
Lwt.async @@ fun () ->
|
||||
Lwt.catch
|
||||
(fun () ->
|
||||
let open Syntax in
|
||||
let+ Mte.{ status; headers; content } =
|
||||
Mte.request_handler (request_from_h2 request)
|
||||
in
|
||||
let response = H2.Response.create ~headers status in
|
||||
H2.Reqd.respond_with_string reqd response content;
|
||||
())
|
||||
(fun exn ->
|
||||
H2.Reqd.report_exn reqd exn;
|
||||
Lwt.return_unit)
|
||||
|
||||
let alpn_request_handler : type reqd headers request response ro wo.
|
||||
reqd -> (reqd, headers, request, response, ro, wo) Alpn.protocol -> unit =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue