X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=examples%2FSSL.hs;h=23de8b04062c4d6b48b80b2b525ae913aab7610c;hp=b9b76a3919e7c12f7930c08b2714f5d47d568637;hb=9be2b946657c536a4363a076235f70728be087c4;hpb=3baf479eba12bc3e9c4ef966df770cd70aa5cd81 diff --git a/examples/SSL.hs b/examples/SSL.hs index b9b76a3..23de8b0 100644 --- a/examples/SSL.hs +++ b/examples/SSL.hs @@ -5,9 +5,10 @@ , 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.HTTP.Lucu import OpenSSL @@ -26,29 +27,31 @@ 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 [] + runHttpd config $ resourceMap tree -helloWorld ∷ ResourceDef +helloWorld ∷ Resource helloWorld - = emptyResource { - resGet - = Just $ 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 - } + = C.fromList + [ ( 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 @@ -61,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