-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from mirleft/prepare
Prepare release
- Loading branch information
Showing
9 changed files
with
62 additions
and
54 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
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
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
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,44 +1,43 @@ | ||
|
||
open Lwt | ||
open Lwt.Infix | ||
open V1_LWT | ||
|
||
module Main (C : CONSOLE) | ||
(S : STACKV4) | ||
(KV : KV_RO) = | ||
(KV : KV_RO) | ||
(CL : V1.CLOCK) = | ||
struct | ||
|
||
module TLS = Tls_mirage.Make (S.TCPV4) | ||
module X509 = Tls_mirage.X509 (KV) (Clock) | ||
module X509 = Tls_mirage.X509 (KV) (CL) | ||
module Http = Cohttp_mirage.Server (TLS) | ||
|
||
module Body = Cohttp_lwt_body | ||
|
||
let handle c conn req body = | ||
let resp = Cohttp.Response.make ~status:`OK () in | ||
lwt body = | ||
lwt inlet = match Cohttp.Request.meth req with | ||
| `POST -> | ||
lwt contents = Body.to_string body in | ||
return @@ "<pre>" ^ contents ^ "</pre>" | ||
| _ -> return "" in | ||
return @@ Body.of_string @@ | ||
"<html><head><title>ohai</title></head> | ||
<body><h3>Secure CoHTTP on-line.</h3>" | ||
^ inlet ^ "</body></html>\r\n" | ||
(match Cohttp.Request.meth req with | ||
| `POST -> | ||
Body.to_string body >|= fun contents -> | ||
"<pre>" ^ contents ^ "</pre>" | ||
| _ -> Lwt.return "") >|= fun inlet -> | ||
let body = Body.of_string @@ | ||
"<html><head><title>ohai</title></head> \ | ||
<body><h3>Secure CoHTTP on-line.</h3>" | ||
^ inlet ^ "</body></html>\r\n" | ||
in | ||
return (resp, body) | ||
(resp, body) | ||
|
||
let upgrade c conf tcp = | ||
TLS.server_of_flow conf tcp >>= function | ||
| `Error _ | `Eof -> fail (Failure "tls init") | ||
| `Ok tls -> | ||
let t = Http.make (handle c) () in | ||
Http.listen t tls | ||
| `Error _ | `Eof -> Lwt.fail (Failure "tls init") | ||
| `Ok tls -> | ||
let t = Http.make (handle c) () in | ||
Http.listen t tls | ||
|
||
let start c stack kv = | ||
lwt cert = X509.certificate kv `Default in | ||
let start c stack kv _ _ = | ||
X509.certificate kv `Default >>= fun cert -> | ||
let conf = Tls.Config.server ~certificates:(`Single cert) () in | ||
S.listen_tcpv4 stack 4433 (upgrade c conf) ; | ||
S.listen_tcpv4 stack ~port:4433 (upgrade c conf) ; | ||
S.listen stack | ||
|
||
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