Skip to content

Commit

Permalink
Merge pull request aantron#55 from dinosaure/with-flow
Browse files Browse the repository at this point in the history
Let the user to manipulate the flow if he/she wants
  • Loading branch information
dinosaure authored Dec 23, 2021
2 parents 4d1b07a + c74dcc1 commit 2661b78
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/paf_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ module type S = sig
val http_service :
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(dst -> Httpaf.Server_connection.request_handler) ->
(TCP.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.service

val https_service :
tls:Tls.Config.server ->
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(dst -> Httpaf.Server_connection.request_handler) ->
(TLS.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.service

val serve :
Expand Down Expand Up @@ -194,7 +194,7 @@ module Make (Time : Mirage_time.S) (Stack : Tcpip.Stack.V4V6) :
let connection flow =
let dst = Stack.TCP.dst flow in
let error_handler = error_handler dst in
let request_handler = request_handler dst in
let request_handler = request_handler flow dst in
let conn =
Httpaf.Server_connection.create ?config ~error_handler request_handler
in
Expand Down Expand Up @@ -225,7 +225,7 @@ module Make (Time : Mirage_time.S) (Stack : Tcpip.Stack.V4V6) :
Stack.TCP.close flow >>= fun () -> Lwt.return_error err) in
let connection (dst, flow) =
let error_handler = error_handler dst in
let request_handler = request_handler dst in
let request_handler = request_handler flow dst in
let conn =
Httpaf.Server_connection.create ?config ~error_handler request_handler
in
Expand Down
4 changes: 2 additions & 2 deletions lib/paf_mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module type S = sig
val http_service :
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(dst -> Httpaf.Server_connection.request_handler) ->
(TCP.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.service
(** [http_service ~error_handler request_handler] makes an HTTP/AF service
where any HTTP/1.1 requests are handled by [request_handler]. The returned
Expand All @@ -39,7 +39,7 @@ module type S = sig
tls:Tls.Config.server ->
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(dst -> Httpaf.Server_connection.request_handler) ->
(TLS.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.service
(** [https_service ~tls ~error_handler request_handler] makes an HTTP/AF
service over TLS (from the given TLS configuration). Then, HTTP/1.1
Expand Down
2 changes: 1 addition & 1 deletion test/simple_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let http_ping_pong (_ip, _port) ic oc =
Lwt.return_unit in
Lwt.async go

let request_handler large (ip, port) reqd =
let request_handler large _flow (ip, port) reqd =
let open Httpaf in
let request = Reqd.request reqd in
match request.Request.target with
Expand Down
5 changes: 3 additions & 2 deletions test/test_cohttp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ let run_http_and_https_server ~request_handler stop =
unix_stack () >|= Tcpip_stack_socket.V4V6.tcp >>= fun stack ->
P.init ~port:9090 stack >>= fun socket0 ->
P.init ~port:3434 stack >>= fun socket1 ->
let http = P.http_service ~error_handler request_handler in
let https = P.https_service ~tls ~error_handler request_handler in
let http = P.http_service ~error_handler (fun _flow -> request_handler) in
let https =
P.https_service ~tls ~error_handler (fun _flow -> request_handler) in
let (`Initialized fiber0) = P.serve ~stop http socket0 in
let (`Initialized fiber1) = P.serve ~stop https socket1 in
Logs.debug (fun m -> m "Server initialised.") ;
Expand Down

0 comments on commit 2661b78

Please sign in to comment.