Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Checkpoint: remove cereal, bytestring-show dependencies, add blaze-bu…

…ilder
  • Loading branch information...
commit 7f65679d0d5737063b3294b2e5961c7b4244bb16 1 parent a352cd7
@gregorycollins gregorycollins authored
View
4 snap-core.cabal
@@ -1,5 +1,5 @@
name: snap-core
-version: 0.3.0
+version: 0.4.0
synopsis: Snap: A Haskell Web Framework (Core)
description:
@@ -141,9 +141,9 @@ Library
build-depends:
attoparsec >= 0.8.0.2 && < 0.9,
base >= 4 && < 5,
+ blaze-builder >= 0.2.1 && <0.3,
bytestring,
bytestring-nums,
- bytestring-show >= 0.3.2 && < 0.4,
cereal >= 0.3 && < 0.4,
containers,
deepseq >= 1.1 && <1.2,
View
10 src/Snap/Internal/Http/Types.hs
@@ -16,6 +16,7 @@ module Snap.Internal.Http.Types where
------------------------------------------------------------------------------
+import Blaze.ByteString.Builder
import Control.Applicative hiding (empty)
import Control.Monad (liftM, when)
import qualified Data.Attoparsec as Atto
@@ -38,7 +39,6 @@ import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Data.Monoid
-import Data.Serialize.Builder
import Data.Time.Clock
import Data.Time.Format
import Data.Word
@@ -731,13 +731,13 @@ urlDecode = parseToCompletion pUrlEscaped
-- | URL-escapes a string (see
-- <http://tools.ietf.org/html/rfc2396.html#section-2.4>)
urlEncode :: ByteString -> ByteString
-urlEncode = toByteString . S.foldl' f empty
+urlEncode = toByteString . S.foldl' f mempty
where
f b c =
if c == c2w ' '
- then b `mappend` singleton (c2w '+')
+ then b `mappend` fromWord8 (c2w '+')
else if isKosher c
- then b `mappend` singleton c
+ then b `mappend` fromWord8 c
else b `mappend` hexd c
isKosher w = any ($ c) [ isAlphaNum
@@ -749,7 +749,7 @@ urlEncode = toByteString . S.foldl' f empty
------------------------------------------------------------------------------
hexd :: Word8 -> Builder
-hexd c = singleton (c2w '%') `mappend` singleton hi `mappend` singleton low
+hexd c = fromWord8 (c2w '%') `mappend` fromWord8 hi `mappend` fromWord8 low
where
d = c2w . intToDigit
low = d $ fromEnum $ c .&. 0xf
View
27 src/Snap/Util/FileServe.hs
@@ -16,23 +16,25 @@ module Snap.Util.FileServe
) where
------------------------------------------------------------------------------
+import Blaze.ByteString.Builder
+import Blaze.ByteString.Builder.Char8
import Control.Applicative
import Control.Monad
import Control.Monad.Trans
import Data.Attoparsec.Char8 hiding (Done)
import qualified Data.ByteString.Char8 as S
-import qualified Data.ByteString.Lazy.Char8 as L
import Data.ByteString.Char8 (ByteString)
+import Data.ByteString.Internal (c2w)
import Data.Int
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe, isNothing)
+import Data.Monoid
import Prelude hiding (show, Show)
import qualified Prelude
import System.Directory
import System.FilePath
import System.PosixCompat.Files
-import Text.Show.ByteString hiding (runPut)
------------------------------------------------------------------------------
import Snap.Internal.Debug
import Snap.Internal.Parsing
@@ -385,14 +387,13 @@ checkRangeReq req fp sz = do
send206 start end = do
dbg "inside send206"
let len = end-start+1
- let crng = S.concat $
- L.toChunks $
- L.concat [ "bytes "
- , show start
- , "-"
- , show end
- , "/"
- , show sz ]
+ let crng = toByteString $
+ mconcat [ fromByteString "bytes "
+ , fromShow start
+ , fromWord8 (c2w '-')
+ , fromShow end
+ , fromWord8 (c2w '/')
+ , fromShow sz ]
modifyResponse $ setResponseCode 206
. setHeader "Content-Range" crng
@@ -413,9 +414,9 @@ checkRangeReq req fp sz = do
if getHeader "If-Range" req /= Nothing
then return False
else do
- let crng = S.concat $
- L.toChunks $
- L.concat ["bytes */", show sz]
+ let crng = toByteString $
+ mconcat [ fromByteString "bytes */"
+ , fromShow sz ]
modifyResponse $ setResponseCode 416
. setHeader "Content-Range" crng
Please sign in to comment.
Something went wrong with that request. Please try again.