on master help sign in
Add 'warp-static/' from commit 'd4952acae927456b45538582afeb23887dfce1ec'

git-subtree-dir: warp-static git-subtree-mainline: aa4ee7eab60f16f63456f42537b940d6d2cce131 git-subtree-split: d4952acae927456b45538582afeb23887dfce1ec

commit2db47661beace40ff992dc0b03963e6c9303f50f authorMichael Snoyman <michael@snoyman.com> dateFri 22 Jul 2011, 16:50 (15 years ago) parentaa4ee7ed4952ac
5 files changed+107
warp-static/LICENSE+30 warp-static/README warp-static/Setup.hs+2 warp-static/warp-static.cabal+24 warp-static/warp.hs+51
warp-static/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c)2011, Michael Snoyman
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 Michael Snoyman 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.
warp-static/READMEnew file

No changes to the content.

warp-static/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
warp-static/warp-static.cabalnew file+24
@@ -0,0 +1,24 @@
1+Name: warp-static
2+Version: 0.2.0
3+Synopsis: Static file server based on Warp and wai-app-static
4+Homepage: http://github.com/snoyberg/warp-static
5+License: BSD3
6+License-file: LICENSE
7+Author: Michael Snoyman
8+Maintainer: michael@snoyman.com
9+Category: Web
10+Build-type: Simple
11+Cabal-version: >=1.2
12+
13+
14+Executable warp
15+ Main-is: warp.hs
16+ Build-depends: base >= 4 && < 5
17+ , warp >= 0.4 && < 0.5
18+ , wai-app-static >= 0.3 && < 0.4
19+ , wai-extra >= 0.4 && < 0.5
20+ , cmdargs >= 0.6.7 && < 0.8
21+ , directory >= 1.0 && < 1.2
22+ , containers >= 0.2 && < 0.5
23+ , bytestring >= 0.9 && < 0.10
24+ , text < 1.0
warp-static/warp.hsnew file+51
@@ -0,0 +1,51 @@
1+{-# LANGUAGE DeriveDataTypeable, RecordWildCards #-}
2+import Network.Wai.Application.Static
3+ ( StaticSettings (..), staticApp, defaultMimeType, defaultListing
4+ , defaultMimeTypes, mimeTypeByExt
5+ , defaultFileServerSettings, fileSystemLookup
6+ , fileName, toFilePath
7+ )
8+import Network.Wai.Handler.Warp (run)
9+import System.Environment (getArgs)
10+import System.Console.CmdArgs
11+import Text.Printf (printf)
12+import System.Directory (canonicalizePath)
13+import Control.Monad (unless)
14+import Network.Wai.Middleware.Autohead
15+import Network.Wai.Middleware.Debug
16+import Network.Wai.Middleware.Gzip
17+import qualified Data.Map as Map
18+import qualified Data.ByteString.Char8 as S8
19+import Control.Arrow ((***))
20+import Data.Text (pack, unpack)
21+
22+data Args = Args
23+ { docroot :: FilePath
24+ , index :: [FilePath]
25+ , port :: Int
26+ , noindex :: Bool
27+ , quiet :: Bool
28+ , verbose :: Bool
29+ , mime :: [(String, String)]
30+ }
31+ deriving (Show, Data, Typeable)
32+
33+defaultArgs = Args "." ["index.html", "index.htm"] 3000 False False False []
34+
35+main :: IO ()
36+main = do
37+ Args {..} <- cmdArgs defaultArgs
38+ let mime' = map (toFilePath *** S8.pack) mime
39+ let mimeMap = Map.fromList mime' `Map.union` defaultMimeTypes
40+ docroot' <- canonicalizePath docroot
41+ args <- getArgs
42+ unless quiet $ printf "Serving directory %s on port %d with %s index files.\n" docroot' port (if noindex then "no" else show index)
43+ let middle = gzip False
44+ . (if verbose then debug else id)
45+ . autohead
46+ run port $ middle $ staticApp defaultFileServerSettings
47+ { ssFolder = fileSystemLookup $ toFilePath docroot
48+ , ssIndices = if noindex then [] else map pack index
49+ , ssListing = Just defaultListing
50+ , ssGetMimeType = return . mimeTypeByExt mimeMap defaultMimeType . fileName
51+ }