X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=examples%2FSSL.hs;h=aa8b3a596ffa29031eb136d5b7587976c4ac3f0e;hb=fffa09842d060c7d738084125dea07783d84aefe;hp=48b23813fbee4f2a746b2940fadf9252cba06965;hpb=ac2ff93f647d60d43ca3cc54eb776fe0f701ac9e;p=Lucu.git diff --git a/examples/SSL.hs b/examples/SSL.hs index 48b2381..aa8b3a5 100644 --- a/examples/SSL.hs +++ b/examples/SSL.hs @@ -1,13 +1,16 @@ {-# LANGUAGE OverloadedStrings , PackageImports + , QuasiQuotes , UnicodeSyntax #-} import Control.Applicative -import "mtl" Control.Monad.Trans +import Control.Monad.IO.Class import Control.Monad.Unicode import qualified Data.ByteString.Lazy.Char8 as Lazy +import qualified Data.Collections as C import Data.Time.Clock +import Network import Network.HTTP.Lucu import OpenSSL import OpenSSL.EVP.PKey @@ -25,29 +28,30 @@ main = withOpenSSL $ SSL.contextSetCertificate ctx cert SSL.contextSetDefaultCiphers ctx - let config = defaultConfig { - cnfServerPort = "9000" - , cnfSSLConfig = Just SSLConfig { - sslServerPort = "9001" - , sslContext = ctx - } - } - resources = mkResTree [ ([], helloWorld) ] + let config = defaultConfig { + cnfServerPort = "9000" + , cnfSSLConfig = Just SSLConfig { + sslServerPort = "9001" + , sslContext = ctx + } + } + tree ∷ ResourceTree + tree = C.fromList [ ([], nonGreedy helloWorld) ] putStrLn "Access https://localhost:9001/ with your browser." - runHttpd config resources [] + withSocketsDo $ runHttpd config $ resourceMap tree -helloWorld ∷ ResourceDef +helloWorld ∷ Resource helloWorld - = emptyResource { - resGet - = Just $ do setContentType $ parseMIMEType "text/plain" - outputChunk "getRemoteCertificate = " - cert ← do cert ← getRemoteCertificate - case cert of - Just c → liftIO $ Lazy.pack <$> printX509 c - Nothing → return "Nothing" - outputChunk cert - } + = C.singleton + ( GET + , do setContentType [mimeType| text/plain |] + putChunk "getRemoteCertificate = " + cert ← do cert ← getRemoteCertificate + case cert of + Just c → liftIO $ Lazy.pack <$> printX509 c + Nothing → return "Nothing" + putChunks cert + ) genCert ∷ KeyPair k ⇒ k → IO X509 genCert pkey @@ -60,4 +64,4 @@ genCert pkey setNotAfter cert =≪ addUTCTime (365 * 24 * 60 * 60) <$> getCurrentTime setPublicKey cert pkey signX509 cert pkey Nothing - return cert \ No newline at end of file + return cert