Commits

Luke Plant committed 30aa625

Only use Char8 ByteString interface where needed

  • Participants
  • Parent commits 22bc1a1

Comments (0)

Files changed (9)

File src/Ella/Framework.hs

 import Ella.Response
 import Ella.Request
 import System.IO (stdout, hClose)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.ByteString.Lazy as BS
 
 -- * Dispatching
 

File src/Ella/GenUtils.hs

 where
 
 import Control.Monad (liftM)
-import Data.ByteString.Lazy.Char8 (ByteString)
+import Data.ByteString.Lazy (ByteString)
 import GHC.Exts( IsString(..) )
 import Random (randomRs, newStdGen)
 import System.Posix.Time (epochTime)

File src/Ella/Request.hs

 
 where
 
-import Data.ByteString.Lazy.Char8 (ByteString)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import Data.ByteString.Lazy (ByteString)
+import Data.ByteString.Lazy.Char8 (pack, unpack)
+import qualified Data.ByteString.Lazy as BS
 import qualified Data.ByteString.Lazy.UTF8 as UTF8
 import Data.List (partition)
 import qualified Data.Map as Map
 --
 -- PATH_INFO and other vars contains Haskell Strings, but in reality these are
 -- simply the bytes obtained from the environment packed into Unicode chars one
--- byte at a time.  We re-pack them into a ByteString (BS.pack discards anything
+-- byte at a time.  We re-pack them into a ByteString (pack discards anything
 -- > \255, which includes nothing in this case), and then re-interpret.
 repack :: String -> Encoding -> String
-repack str encoding = let bytes = BS.pack str
+repack str encoding = let bytes = pack str
                       in (decoder encoding) bytes
 
 -- | Returns the URI requested by the client, with percent encoding intact
 -- | Escapes a string of bytes with percent encoding
 escapePath :: ByteString -> String
 -- Borrowed from Network.URI
-escapePath bs = escapeURIString isUnescapedInURIPath $ BS.unpack bs
+escapePath bs = escapeURIString isUnescapedInURIPath $ unpack bs
   where isUnescapedInURIPath c = isUnescapedInURI c && c `notElem` "?#"
 
 -- | Escapes a unicode string with percent encoding, using the supplied
 decodeBody ctype inp enc =
     case ctype of
                Just (ContentType "application" "x-www-form-urlencoded" _)
-                   -> (formInputEnc (BS.unpack inp) enc, [])
+                   -> (formInputEnc (unpack inp) enc, [])
                Just (ContentType "multipart" "form-data" ps)
                    -> multipartDecode ps inp enc
                Just _ -> ([], []) -- unknown content-type, the user will have to
                                   -- deal with it by looking at the raw content
                -- No content-type given, assume x-www-form-urlencoded
-               Nothing -> (formInputEnc (BS.unpack inp) enc, [])
+               Nothing -> (formInputEnc (unpack inp) enc, [])
 
 
 -- | Decodes multipart\/form-data input.

File src/Ella/Response.hs

                     , formatResponse
                     ) where
 
-import Data.ByteString.Lazy.Char8 (ByteString)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import Data.ByteString.Lazy (ByteString)
+import Data.ByteString.Lazy.Char8 (pack)
+import qualified Data.ByteString.Lazy as BS
 import Data.List (intersperse)
 import Ella.CGI.Header (Headers, HeaderName(HeaderName))
 import Network.CGI (ContentType(ContentType), showContentType)
 formatResponse resp =
     -- NOTE: we use CRLF since lighttpd mod_fastcgi can't handle
     -- just LF if there are CRs in the content.
-    unlinesCrLf ([BS.pack (n++": "++v) | (HeaderName n,v) <- allHeaders resp]
+    unlinesCrLf ([pack (n++": "++v) | (HeaderName n,v) <- allHeaders resp]
                 ++ [BS.empty, content resp])
-  where unlinesCrLf = BS.concat . intersperse (BS.pack "\r\n")
+  where unlinesCrLf = BS.concat . intersperse (pack "\r\n")
 
 
 -- | Create an HTTP 302 redirect

File src/Ella/TestUtils.hs

 import Ella.GenUtils (utf8)
 import Ella.Request
 import Network.CGI (formEncode)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.ByteString.Lazy as BS
 
 
 mkGetReq path = mkRequest [("REQUEST_METHOD", "GET")

File testsuite/Tests/Ella/Framework.hs

 import Ella.Response
 import Test.HUnit
 import Ella.TestUtils (mkGetReq)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.ByteString.Lazy as BS
 
 req1 = mkGetReq "/posts/"
 resp1 = buildResponse [ addContent "resp1" ] utf8HtmlResponse

File testsuite/Tests/Ella/Processors/Security.hs

 import Ella.Response
 import Ella.TestUtils (mkGetReq, mkPostReq, addCookieValues)
 import Test.HUnit
-import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.ByteString.Lazy as BS
 import qualified Data.Map as Map
 
 scp_secret = "test"

File testsuite/Tests/Ella/Request.hs

 where
 
 import qualified Data.Map as Map
-import qualified Data.ByteString.Lazy.Char8 as BS
-import Data.ByteString.Lazy.Char8 (ByteString)
+import qualified Data.ByteString.Lazy as BS
+import Data.ByteString.Lazy (ByteString)
 import Ella.Request
 import Test.HUnit
 import Ella.GenUtils (utf8)

File testsuite/Tests/Ella/Response.hs

 
 import Ella.Response
 import Test.HUnit
-import Data.ByteString.Lazy.Char8 (ByteString)
-import qualified Data.ByteString.Lazy.Char8 as BS
+import Data.ByteString.Lazy (ByteString)
+import qualified Data.ByteString.Lazy as BS
 import Data.List (sort)
 
 testAddContent1 = "“Hello”" ~=? (content $ addContent "“Hello”" $ emptyResponse)