├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Setup.hs ├── Web └── Scotty │ └── TLS.hs ├── default.nix ├── examples └── Main.hs ├── scotty-tls.cabal └── shell.nix /.gitignore: -------------------------------------------------------------------------------- 1 | .hsenv 2 | dist/ 3 | dist-newstyle/ 4 | *~ 5 | *.hi 6 | *.o 7 | TAGS 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | * Remove unnecessary argument to `scottyTTLS` so that `scotty-tls` can build 3 | with `scotty-0.10` and up 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, David Johnson 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of David Johnson nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scotty-TLS 2 | 3 | You can test by generating a self-signed certificate like this: 4 | 5 | ```sh 6 | openssl req -nodes -newkey rsa:2048 -keyout example.key -out example.csr \ 7 | -subj "/C=GB/ST=London/L=London/O=Acme Widgets/OU=IT Department/CN=example.com" 8 | openssl x509 -req -days 365 -in example.csr -signkey example.key -out example.crt 9 | ``` 10 | For more details on making certificates, see [this guide](http://www.akadia.com/services/ssh_test_certificate.html). 11 | 12 | 13 | Install and run with: 14 | 15 | ```text 16 | cabal update && cabal install scotty-tls 17 | ``` 18 | 19 | ```haskell 20 | {-# LANGUAGE OverloadedStrings #-} 21 | 22 | import Data.Monoid (mconcat) 23 | import Web.Scotty 24 | import Web.Scotty.TLS 25 | 26 | main :: IO () 27 | main = scottyTLS 3000 "server.key" "server.crt" $ do 28 | get "/:word" $ do 29 | beam <- param "word" 30 | html $ mconcat ["

Scotty, ", beam, " me up!

"] 31 | ``` 32 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /Web/Scotty/TLS.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE RankNTypes #-} 2 | 3 | module Web.Scotty.TLS 4 | ( -- * A method for running Scotty over TLS 5 | scottyTLS 6 | -- * Transformer version 7 | , scottyTLSSettings 8 | , scottyTTLS 9 | , module Web.Scotty.Trans 10 | ) where 11 | 12 | import Control.Monad ((<=<)) 13 | import Control.Monad.IO.Class (MonadIO (liftIO)) 14 | import Network.Wai (Response) 15 | import Network.Wai.Handler.Warp (Port, defaultSettings, 16 | setPort) 17 | import Network.Wai.Handler.WarpTLS (tlsSettings, 18 | runTLS, TLSSettings(..)) 19 | import Web.Scotty (scottyApp, ScottyM, defaultOptions) 20 | import Web.Scotty.Trans (ScottyT, scottyAppT) 21 | 22 | -- | Run a Scotty application over TLS 23 | scottyTLS :: Port -> FilePath -> FilePath -> ScottyM () -> IO () 24 | scottyTLS port key cert = runTLS 25 | (tlsSettings cert key) 26 | (setPort port defaultSettings) <=< scottyApp 27 | 28 | scottyTLSSettings :: Port -> TLSSettings -> ScottyM () -> IO () 29 | scottyTLSSettings port settings = runTLS 30 | settings 31 | (setPort port defaultSettings) <=< scottyApp 32 | 33 | scottyTTLS 34 | :: (Monad m, MonadIO n) 35 | => Port 36 | -> FilePath 37 | -> FilePath 38 | -> (m Response -> IO Response) 39 | -> ScottyT m () 40 | -> n () 41 | scottyTTLS port key cert runToIO s = do 42 | app <- scottyAppT defaultOptions runToIO s 43 | liftIO $ runTLS 44 | (tlsSettings cert key) 45 | (setPort port defaultSettings) 46 | app 47 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: pkgs.haskellPackages.callCabal2nix "scotty-tls" ./. {} 2 | -------------------------------------------------------------------------------- /examples/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | import Data.Monoid (mconcat) 4 | import Web.Scotty 5 | import Web.Scotty.TLS 6 | 7 | main :: IO () 8 | main = scottyTLS 3000 "server.key" "server.crt" $ do 9 | get "/:word" $ do 10 | beam <- param "word" 11 | html $ mconcat ["

Scotty, ", beam, " me up!

"] 12 | -------------------------------------------------------------------------------- /scotty-tls.cabal: -------------------------------------------------------------------------------- 1 | name: scotty-tls 2 | version: 0.6.0 3 | synopsis: TLS for Scotty 4 | description: Run your Scotty apps over TLS 5 | homepage: https://github.com/dmjio/scotty-tls.git 6 | license: BSD3 7 | license-file: LICENSE 8 | author: David Johnson 9 | maintainer: code@dmj.io 10 | category: Web 11 | build-type: Simple 12 | cabal-version: >=1.10 13 | Extra-source-files: 14 | CHANGELOG.md 15 | README.md 16 | examples/Main.hs 17 | library 18 | exposed-modules: Web.Scotty.TLS 19 | other-extensions: RankNTypes 20 | build-depends: base < 5, 21 | scotty >=0.21.0 && < 0.23, 22 | warp >= 3.3 && < 3.5, 23 | warp-tls >= 3.4 && < 3.5, 24 | wai >= 3.2 && < 3.3, 25 | transformers >= 0.3.0.0 && < 0.7 26 | GHC-options: -Wall -fno-warn-orphans 27 | default-language: Haskell2010 28 | source-repository head 29 | type: git 30 | location: git://github.com/scotty-web/scotty-tls.git 31 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import ./default.nix {}).env 2 | --------------------------------------------------------------------------------