This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
4
unikernel/duniverse/ocaml-h2/examples/alpn/lib/dune
Normal file
4
unikernel/duniverse/ocaml-h2/examples/alpn/lib/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(library
|
||||
(name alpn_lib)
|
||||
(modules h2_handler http1_handler)
|
||||
(libraries h2 httpun httpun-lwt-unix h2-lwt-unix lwt))
|
||||
30
unikernel/duniverse/ocaml-h2/examples/alpn/lib/h2_handler.ml
Normal file
30
unikernel/duniverse/ocaml-h2/examples/alpn/lib/h2_handler.ml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
open H2
|
||||
|
||||
let request_handler : Unix.sockaddr -> Reqd.t -> unit =
|
||||
fun _client_address request_descriptor ->
|
||||
let request = Reqd.request request_descriptor in
|
||||
let response_content_type =
|
||||
match Headers.get request.headers "Content-Type" with
|
||||
| Some request_content_type -> request_content_type
|
||||
| None -> "text/plain"
|
||||
in
|
||||
let response =
|
||||
Response.create
|
||||
~headers:(Headers.of_list [ "content-type", response_content_type ])
|
||||
`OK
|
||||
in
|
||||
Reqd.respond_with_string
|
||||
request_descriptor
|
||||
response
|
||||
"Welcome to an ALPN-negotiated HTTP/2 connection"
|
||||
|
||||
let error_handler :
|
||||
Unix.sockaddr
|
||||
-> ?request:H2.Request.t
|
||||
-> _
|
||||
-> (Headers.t -> Body.Writer.t)
|
||||
-> unit
|
||||
=
|
||||
fun _client_address ?request:_ _error start_response ->
|
||||
let response_body = start_response Headers.empty in
|
||||
Body.Writer.close response_body
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
open Httpun
|
||||
|
||||
let redirect_handler : Unix.sockaddr -> Reqd.t Gluten.reqd -> unit =
|
||||
fun _client_address { Gluten.reqd; _ } ->
|
||||
let response =
|
||||
Response.create
|
||||
~headers:
|
||||
(Headers.of_list
|
||||
[ "Location", "https://localhost:9443"; "Connection", "close" ])
|
||||
`Moved_permanently
|
||||
in
|
||||
Reqd.respond_with_string reqd response ""
|
||||
|
||||
let redirect_error_handler :
|
||||
Unix.sockaddr
|
||||
-> ?request:Request.t
|
||||
-> _
|
||||
-> (Headers.t -> Body.Writer.t)
|
||||
-> unit
|
||||
=
|
||||
fun _client_address ?request:_ _error start_response ->
|
||||
let response_body = start_response Headers.empty in
|
||||
Body.Writer.close response_body
|
||||
|
||||
let request_handler : Unix.sockaddr -> Reqd.t Gluten.reqd -> unit =
|
||||
fun _client_address { Gluten.reqd; _ } ->
|
||||
let request = Reqd.request reqd in
|
||||
let response_content_type =
|
||||
match Headers.get request.headers "Content-Type" with
|
||||
| Some request_content_type -> request_content_type
|
||||
| None -> "text/plain"
|
||||
in
|
||||
let response_body = "Welcome to an ALPN-negotiated HTTP/1.1 connection" in
|
||||
let response =
|
||||
Response.create
|
||||
~headers:
|
||||
(Headers.of_list
|
||||
[ "content-type", response_content_type
|
||||
; "Content-Length", String.length response_body |> string_of_int
|
||||
])
|
||||
`OK
|
||||
in
|
||||
Reqd.respond_with_string reqd response response_body
|
||||
|
||||
let error_handler :
|
||||
Unix.sockaddr
|
||||
-> ?request:Request.t
|
||||
-> _
|
||||
-> (Headers.t -> Body.Writer.t)
|
||||
-> unit
|
||||
=
|
||||
fun _client_address ?request:_ _error start_response ->
|
||||
let response_body = start_response Headers.empty in
|
||||
Body.Writer.close response_body
|
||||
Loading…
Add table
Add a link
Reference in a new issue