package paf
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=24826310211b6a36aea306d7a2dd7dbed883853a4601089208163400764ec993
sha512=2fb74889bad5d5a9164fa77618de1f96a89037a7fbe9b8f849933188fc2432ab4be99b298b871a2831e421963667a974bea3a329a471b5ab0b0787552d622f56
doc/paf.mirage/Paf_mirage/Make/index.html
Module Paf_mirage.MakeSource
Parameters
module Time : Mirage_time.Smodule Stack : Tcpip.Tcp.SSignature
The type of the IP address.
Protocols.
From the given stack, Paf_mirage constructs protocols needed for HTTP:
- A simple TCP/IP protocol
- A TCP/IP protocol wrapped into TLS via
ocaml-tls
We expose these protocols in the sense of mimic. They are registered globally with mimic and are usable via mimic (see Mimic.resolve) as long as the given ctx contains tcp_edn and/or tls_edn.
Such way to instance something which represents these protocols and usable as a Mirage_flow.S are useful for the client-side, see run.
Server implementation.
init ~port stack bounds the given stack to a specific port and return the main socket t.
accept t waits an incoming connection and return a socket connected to a peer.
HTTP/1.1 servers.
The user is able to launch a simple HTTP/1.1 server with TLS or not. Below, you can see a simple example:
let run ~error_handler ~request_handler =
Paf_mirage.init ~port:8080 stack >>= fun t ->
Paf_mirage.http_service ~error_handler request_handler
>>= fun service ->
let (`Initialized th) = Paf_mirage.serve service t in
thval http_service :
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(TCP.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.servicehttp_service ~error_handler request_handler makes an HTTP/AF service where any HTTP/1.1 requests are handled by request_handler. The returned service is not yet launched (see serve).
val https_service :
tls:Tls.Config.server ->
?config:Httpaf.Config.t ->
error_handler:(dst -> Httpaf.Server_connection.error_handler) ->
(TLS.flow -> dst -> Httpaf.Server_connection.request_handler) ->
t Paf.servicehttps_service ~tls ~error_handler request_handler makes an HTTP/AF service over TLS (from the given TLS configuration). Then, HTTP/1.1 requests are handled by request_handler. The returned service is not yet launched (see serve).
HTTP/1.1 & H2 over TLS server.
It's possible to make am ALPN server. It's an HTTP server which can handle
- HTTP/1.1 requests
- and H2 requests
The choice is made by the ALPN challende on the TLS layer where the client can send which protocol he/she wants to use. Therefore, the server must handle these two cases.
val alpn_service :
tls:Tls.Config.server ->
?config:(Httpaf.Config.t * H2.Config.t) ->
error_handler:
(dst ->
?request:Alpn.request ->
Alpn.server_error ->
(Alpn.headers -> Alpn.body) ->
unit) ->
(dst -> Alpn.reqd -> unit) ->
t Paf.servicealpn_service ~tls ~error_handler request_handler makes an H2/HTTP/AF service over TLS (from the given TLS configuration). An HTTP request (version 1.1 or 2) is handled then by request_handler. The returned service is not yet launched (see server).
serve ?stop service returns an initialized promise of the given service service. stop can be used to stop the service.