-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b1e3a5
commit 96b9c60
Showing
18 changed files
with
749 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ | |
|
||
(alias | ||
(name benchmarks) | ||
(deps (glob_files *.exe))) | ||
(deps | ||
(glob_files *.exe))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(lang dune 1.5) | ||
(lang dune 1.0) | ||
|
||
(name httpaf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
(alias | ||
(name examples) | ||
(deps (glob_files *.exe))) | ||
(deps | ||
(glob_files *.exe))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open Mirage | ||
|
||
(* Network configuration *) | ||
|
||
let stack = generic_stackv4 default_network | ||
|
||
(* Dependencies *) | ||
|
||
let server = | ||
foreign "Unikernel.Make" | ||
(console @-> pclock @-> http @-> job) | ||
|
||
let app = | ||
httpaf_server @@ conduit_direct stack | ||
|
||
let () = | ||
register "httpaf_unikernel" | ||
[ server $ default_console $ default_posix_clock $ app ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
open Lwt.Infix | ||
open Httpaf | ||
|
||
module type HTTP = Httpaf_mirage.Server_intf | ||
|
||
module Dispatch (C: Mirage_types_lwt.CONSOLE) (Http: HTTP) = struct | ||
|
||
let log c fmt = Printf.ksprintf (C.log c) fmt | ||
|
||
let get_content c path = | ||
log c "Replying: %s" path >|= fun () -> | ||
"Hello from the httpaf unikernel" | ||
|
||
let dispatcher c reqd = | ||
let {Request.target; _} = Reqd.request reqd in | ||
Lwt.catch | ||
(fun () -> | ||
get_content c target >|= fun body -> | ||
let response = Response.create | ||
~headers:(Headers.of_list ["Content-Length", body | ||
|> String.length | ||
|> string_of_int]) | ||
`OK | ||
in | ||
Reqd.respond_with_string reqd response body) | ||
(fun exn -> | ||
let response = Response.create `Internal_server_error in | ||
Lwt.return (Reqd.respond_with_string reqd response (Printexc.to_string exn))) | ||
|> ignore | ||
|
||
let serve c dispatch = | ||
let error_handler ?request:_ _error mk_response = | ||
let response_body = mk_response Headers.empty in | ||
Body.write_string response_body "Error handled"; | ||
Body.flush response_body (fun () -> Body.close_writer response_body) | ||
in | ||
Http.create_connection_handler | ||
?config:None | ||
~request_handler:(dispatch c) | ||
~error_handler | ||
end | ||
|
||
(** Server boilerplate *) | ||
module Make (C : Mirage_types_lwt.CONSOLE) (Clock : Mirage_types_lwt.PCLOCK) (Http: HTTP) = struct | ||
|
||
module D = Dispatch (C) (Http) | ||
|
||
let log c fmt = Printf.ksprintf (C.log c) fmt | ||
let start c _clock http = | ||
log c "started unikernel listen on port 8001" >>= fun () -> | ||
http (`TCP 8001) @@ D.serve c D.dispatcher | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
opam-version: "2.0" | ||
name: "httpaf-lwt" | ||
maintainer: "Spiros Eliopoulos <[email protected]>" | ||
authors: [ | ||
"Anton Bachin <[email protected]>" | ||
"Spiros Eliopoulos <[email protected]>" | ||
] | ||
license: "BSD-3-clause" | ||
homepage: "https://github.com/inhabitedtype/httpaf" | ||
bug-reports: "https://github.com/inhabitedtype/httpaf/issues" | ||
dev-repo: "git+https://github.com/inhabitedtype/httpaf.git" | ||
build: [ | ||
["dune" "build" "-p" name "-j" jobs] | ||
] | ||
depends: [ | ||
"ocaml" {>= "4.03.0"} | ||
"httpaf" | ||
"dune" {build} | ||
"lwt" | ||
] | ||
synopsis: "Lwt support for http/af" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
opam-version: "2.0" | ||
name: "httpaf-mirage" | ||
maintainer: "Antonio Nuno Monteiro <[email protected]>" | ||
authors: [ "Antonio Nuno Monteiro <[email protected]>" | ||
"Spiros Eliopoulos <[email protected]>" ] | ||
license: "BSD-3-clause" | ||
homepage: "https://github.com/inhabitedtype/httpaf" | ||
bug-reports: "https://github.com/inhabitedtype/httpaf/issues" | ||
dev-repo: "git+https://github.com/inhabitedtype/httpaf.git" | ||
build: [ | ||
["dune" "build" "-p" name] | ||
] | ||
depends: [ | ||
"ocaml" {>= "4.03.0"} | ||
"faraday-lwt" | ||
"httpaf" | ||
"httpaf-lwt" | ||
"mirage-conduit" | ||
"cstruct" | ||
"dune" {build} | ||
"lwt" | ||
] | ||
pin-depends: [ | ||
[ "httpaf.dev" "git+https://github.com/anmonteiro/httpaf.git#fork" ] | ||
[ "httpaf-lwt.dev" "git+https://github.com/anmonteiro/httpaf.git#fork" ] | ||
] | ||
synopsis: "Mirage support for http/af" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
(library | ||
(name httpaf_lwt_unix) | ||
(public_name httpaf-lwt-unix) | ||
(libraries faraday-lwt-unix httpaf lwt.unix) | ||
(flags (:standard -safe-string))) | ||
(libraries faraday-lwt-unix httpaf httpaf-lwt lwt.unix) | ||
(flags | ||
(:standard -safe-string))) |
Oops, something went wrong.