on master help sign in
drop blaze-builder dependency for wai-extra
commitde81a1be90b7ccf32ffe73af8bbe8290445f8480 authorMichael Karg <mgoremeier@gmail.com> dateMon 12 Mar 2018, 00:23 (9 years ago) parent2cc5c4a
11 files changed+54−68
wai-extra/ChangeLog.md+4 wai-extra/Network/Wai/EventSource/EventStream.hs+8−9 wai-extra/Network/Wai/Handler/CGI.hs+14−23 wai-extra/Network/Wai/Header.hs+1−1 wai-extra/Network/Wai/Middleware/Gzip.hs+3−12 wai-extra/Network/Wai/Middleware/Jsonp.hs+7−7 wai-extra/Network/Wai/Middleware/RequestLogger.hs+2−2 wai-extra/Network/Wai/Middleware/RequestLogger/JSON.hs+3−2 wai-extra/Network/Wai/Test.hs+3−4 wai-extra/test/Network/Wai/TestSpec.hs+5−1 wai-extra/wai-extra.cabal+4−7
wai-extra/ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 3.0.22.1
2+
3+* Drop dependency on blaze-builder, requiring streaming-commons >= 0.2
4+
15## 3.0.22.0
26
37* Support for streaming-commons 0.2
wai-extra/Network/Wai/EventSource/EventStream.hs+8−9
@@ -9,8 +9,7 @@ module Network.Wai.EventSource.EventStream (
99 eventToBuilder
1010 ) where
1111
12−import Blaze.ByteString.Builder
13−import Blaze.ByteString.Builder.Char8
12+import Data.ByteString.Builder
1413#if __GLASGOW_HASKELL__ < 710
1514import Data.Monoid
1615#endif
@@ -39,18 +38,18 @@ data ServerEvent
3938 Newline as a Builder.
4039-}
4140nl :: Builder
42−nl = fromChar '\n'
41+nl = char7 '\n'
4342
4443
4544{-|
4645 Field names as Builder
4746-}
4847nameField, idField, dataField, retryField, commentField :: Builder
49−nameField = fromString "event:"
50−idField = fromString "id:"
51−dataField = fromString "data:"
52−retryField = fromString "retry:"
53−commentField = fromChar ':'
48+nameField = string7 "event:"
49+idField = string7 "id:"
50+dataField = string7 "data:"
51+retryField = string7 "retry:"
52+commentField = char7 ':'
5453
5554
5655{-|
@@ -66,7 +65,7 @@ field l b = l `mappend` b `mappend` nl
6665-}
6766eventToBuilder :: ServerEvent -> Maybe Builder
6867eventToBuilder (CommentEvent txt) = Just $ field commentField txt
69−eventToBuilder (RetryEvent n) = Just $ field retryField (fromShow n)
68+eventToBuilder (RetryEvent n) = Just $ field retryField (string8 . show $ n)
7069eventToBuilder (CloseEvent) = Nothing
7170eventToBuilder (ServerEvent n i d)= Just $
7271 (name n $ evid i $ mconcat (map (field dataField) d)) `mappend` nl
wai-extra/Network/Wai/Handler/CGI.hs+14−23
@@ -19,8 +19,8 @@ import Control.Arrow ((***))
1919import Data.Char (toLower)
2020import qualified System.IO
2121import qualified Data.String as String
22−import Blaze.ByteString.Builder (fromByteString, toLazyByteString, flush)
23−import Blaze.ByteString.Builder.Char8 (fromChar, fromString)
22+import Data.ByteString.Builder (byteString, toLazyByteString, char7, string8)
23+import Data.ByteString.Builder.Extra (flush)
2424import Data.ByteString.Lazy.Internal (defaultChunkSize)
2525import System.IO (Handle)
2626import Network.HTTP.Types (Status (..), hRange, hContentType, hContentLength)
@@ -30,12 +30,7 @@ import qualified Data.CaseInsensitive as CI
3030import Data.Monoid (mconcat, mempty, mappend)
3131#endif
3232
33−#if MIN_VERSION_streaming_commons(0, 2, 0)
3433import qualified Data.Streaming.ByteString.Builder as Blaze
35−#else
36−import qualified Data.Streaming.Blaze as Blaze
37−#endif
38−
3934import Data.Function (fix)
4035import Control.Monad (unless, void)
4136
@@ -136,11 +131,7 @@ runGeneric vars inputH outputH xsendfile app = do
136131 return ResponseReceived
137132 _ -> do
138133 let (s, hs, wb) = responseToStream res
139−#if MIN_VERSION_streaming_commons(0, 2, 0)
140134 (blazeRecv, blazeFinish) <- Blaze.newBuilderRecv Blaze.defaultStrategy
141−#else
142− (blazeRecv, blazeFinish) <- Blaze.newBlazeRecv Blaze.defaultStrategy
143−#endif
144135 wb $ \b -> do
145136 let sendBuilder builder = do
146137 popper <- blazeRecv builder
@@ -149,30 +140,30 @@ runGeneric vars inputH outputH xsendfile app = do
149140 unless (B.null bs) $ do
150141 outputH bs
151142 loop
152− sendBuilder $ headers s hs `mappend` fromChar '\n'
143+ sendBuilder $ headers s hs `mappend` char7 '\n'
153144 b sendBuilder (sendBuilder flush)
154145 blazeFinish >>= maybe (return ()) outputH
155146 return ResponseReceived
156147 where
157148 headers s hs = mconcat (map header $ status s : map header' (fixHeaders hs))
158− status (Status i m) = (fromByteString "Status", mconcat
159− [ fromString $ show i
160− , fromChar ' '
161− , fromByteString m
149+ status (Status i m) = (byteString "Status", mconcat
150+ [ string8 $ show i
151+ , char7 ' '
152+ , byteString m
162153 ])
163− header' (x, y) = (fromByteString $ CI.original x, fromByteString y)
154+ header' (x, y) = (byteString $ CI.original x, byteString y)
164155 header (x, y) = mconcat
165156 [ x
166− , fromByteString ": "
157+ , byteString ": "
167158 , y
168− , fromChar '\n'
159+ , char7 '\n'
169160 ]
170161 sfBuilder s hs sf fp = mconcat
171162 [ headers s hs
172− , header $ (fromByteString sf, fromString fp)
173− , fromChar '\n'
174− , fromByteString sf
175− , fromByteString " not supported"
163+ , header $ (byteString sf, string8 fp)
164+ , char7 '\n'
165+ , byteString sf
166+ , byteString " not supported"
176167 ]
177168 fixHeaders h =
178169 case lookup hContentType h of
wai-extra/Network/Wai/Header.hs+1−1
@@ -14,5 +14,5 @@ contentLength hdrs = lookup H.hContentLength hdrs >>= readInt
1414readInt :: S8.ByteString -> Maybe Integer
1515readInt bs =
1616 case S8.readInteger bs of
17− Just (i, "") -> Just i
17+ Just (i, rest) | S8.null rest -> Just i
1818 _ -> Nothing
wai-extra/Network/Wai/Middleware/Gzip.hs+3−12
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
21{-# LANGUAGE Rank2Types, ScopedTypeVariables #-}
32---------------------------------------------------------
43-- |
@@ -31,18 +30,14 @@ import Data.Default.Class
3130import Network.HTTP.Types ( Status, Header, hContentEncoding, hUserAgent
3231 , hContentType, hContentLength)
3332import System.Directory (doesFileExist, createDirectoryIfMissing)
34−import Blaze.ByteString.Builder (fromByteString)
33+import Data.ByteString.Builder (byteString)
34+import qualified Data.ByteString.Builder.Extra as Blaze (flush)
3535import Control.Exception (try, SomeException)
3636import qualified Data.Set as Set
3737import Network.Wai.Header
3838import Network.Wai.Internal
39−#if MIN_VERSION_streaming_commons(0, 2, 0)
4039import qualified Data.Streaming.ByteString.Builder as B
41−#else
42−import qualified Data.Streaming.Blaze as B
43−#endif
4440import qualified Data.Streaming.Zlib as Z
45−import qualified Blaze.ByteString.Builder as Blaze
4641import Control.Monad (unless)
4742import Data.Function (fix)
4843import Control.Exception (throwIO)
@@ -187,11 +182,7 @@ compressE set res sendResponse =
187182 Just m | gzipCheckMime set m ->
188183 let hs' = fixHeaders hs
189184 in wb $ \body -> sendResponse $ responseStream s hs' $ \sendChunk flush -> do
190−#if MIN_VERSION_streaming_commons(0, 2, 0)
191185 (blazeRecv, _) <- B.newBuilderRecv B.defaultStrategy
192−#else
193− (blazeRecv, _) <- B.newBlazeRecv B.defaultStrategy
194−#endif
195186 deflate <- Z.initDeflate 1 (Z.WindowBits 31)
196187 let sendBuilder builder = do
197188 popper <- blazeRecv builder
@@ -210,7 +201,7 @@ compressE set res sendResponse =
210201 case result of
211202 Z.PRDone -> return ()
212203 Z.PRNext bs' -> do
213− sendChunk $ fromByteString bs'
204+ sendChunk $ byteString bs'
214205 loop
215206 Z.PRError e -> throwIO e
216207
wai-extra/Network/Wai/Middleware/Jsonp.hs+7−7
@@ -18,8 +18,8 @@ import Network.Wai
1818import Network.Wai.Internal
1919import Data.ByteString (ByteString)
2020import qualified Data.ByteString.Char8 as B8
21−import Blaze.ByteString.Builder (copyByteString)
22−import Blaze.ByteString.Builder.Char8 (fromChar)
21+import Data.ByteString.Builder.Extra (byteStringCopy)
22+import Data.ByteString.Builder (char7)
2323#if __GLASGOW_HASKELL__ < 710
2424import Data.Monoid (mappend)
2525#endif
@@ -60,10 +60,10 @@ jsonp app env sendResponse = do
6060 sendResponse $ case checkJSON hs of
6161 Nothing -> r
6262 Just hs' -> responseBuilder s hs' $
63− copyByteString c
64− `mappend` fromChar '('
63+ byteStringCopy c
64+ `mappend` char7 '('
6565 `mappend` b
66− `mappend` fromChar ')'
66+ `mappend` char7 ')'
6767 go c r =
6868 case checkJSON hs of
6969 Just hs' -> addCallback c s hs' wb
@@ -81,9 +81,9 @@ jsonp app env sendResponse = do
8181
8282 addCallback cb s hs wb =
8383 wb $ \body -> sendResponse $ responseStream s hs $ \sendChunk flush -> do
84− sendChunk $ copyByteString cb `mappend` fromChar '('
84+ sendChunk $ byteStringCopy cb `mappend` char7 '('
8585 _ <- body sendChunk flush
86− sendChunk $ fromChar ')'
86+ sendChunk $ char7 ')'
8787
8888changeVal :: Eq a
8989 => a
wai-extra/Network/Wai/Middleware/RequestLogger.hs+2−2
@@ -20,7 +20,7 @@ module Network.Wai.Middleware.RequestLogger
2020 ) where
2121
2222import System.IO (Handle, hFlush, stdout)
23−import qualified Blaze.ByteString.Builder as B
23+import qualified Data.ByteString.Builder as B (Builder, byteString)
2424import qualified Data.ByteString as BS
2525import Data.ByteString.Char8 (pack)
2626import Control.Monad (when)
@@ -130,7 +130,7 @@ customMiddlewareWithDetails cb getdate formatter app req sendResponse = do
130130 t1 <- getCurrentTime
131131 date <- liftIO getdate
132132 -- We use Nothing for the response size since we generally don't know it
133− builderIO <- newIORef $ B.fromByteString ""
133+ builderIO <- newIORef $ B.byteString ""
134134 res' <- recordChunks builderIO res
135135 rspRcv <- sendResponse res'
136136 _ <- liftIO . cb .
wai-extra/Network/Wai/Middleware/RequestLogger/JSON.hs+3−2
@@ -2,7 +2,8 @@
22
33module Network.Wai.Middleware.RequestLogger.JSON (formatAsJSON) where
44
5−import qualified Blaze.ByteString.Builder as BB
5+import qualified Data.ByteString.Builder as BB (toLazyByteString)
6+import Data.ByteString.Lazy (toStrict)
67import Data.Aeson
78import Data.CaseInsensitive (original)
89import Data.Monoid ((<>))
@@ -31,7 +32,7 @@ formatAsJSON date req status responseSize duration reqBody response =
3132 , "size" .= responseSize
3233 , "body" .=
3334 if statusCode status >= 400
34− then Just . decodeUtf8 . BB.toByteString $ response
35+ then Just . decodeUtf8 . toStrict . BB.toLazyByteString $ response
3536 else Nothing
3637 ]
3738 , "time" .= decodeUtf8 date
wai-extra/Network/Wai/Test.hs+3−4
@@ -52,8 +52,7 @@ import qualified Data.Map as Map
5252import qualified Web.Cookie as Cookie
5353import Data.ByteString (ByteString)
5454import qualified Data.ByteString.Char8 as S8
55−import Blaze.ByteString.Builder (toLazyByteString, toByteString)
56−import qualified Blaze.ByteString.Builder as B
55+import Data.ByteString.Builder (toLazyByteString)
5756import qualified Data.ByteString.Lazy as L
5857import qualified Data.ByteString.Lazy.Char8 as L8
5958import qualified Network.HTTP.Types as H
@@ -114,7 +113,7 @@ request = srequest . flip SRequest L.empty
114113setPath :: Request -> S8.ByteString -> Request
115114setPath req path = req {
116115 pathInfo = segments
117− , rawPathInfo = B.toByteString (H.encodePathSegments segments)
116+ , rawPathInfo = (L8.toStrict . toLazyByteString) (H.encodePathSegments segments)
118117 , queryString = query
119118 , rawQueryString = (H.renderQuery True query)
120119 }
@@ -143,7 +142,7 @@ addCookiesToRequest req = do
143142 let cookiePairs = [ (Cookie.setCookieName c, Cookie.setCookieValue c)
144143 | c <- map snd $ Map.toList cookiesForRequest
145144 ]
146− let cookieValue = toByteString $ Cookie.renderCookies cookiePairs
145+ let cookieValue = L8.toStrict . toLazyByteString $ Cookie.renderCookies cookiePairs
147146 addCookieHeader rest
148147 | null cookiePairs = rest
149148 | otherwise = ("Cookie", cookieValue) : rest
wai-extra/test/Network/Wai/TestSpec.hs+5−1
@@ -16,13 +16,17 @@ import Network.Wai.Test
1616import Network.HTTP.Types (status200)
1717
1818import qualified Data.ByteString.Lazy.Char8 as L8
19−import Blaze.ByteString.Builder (toByteString)
19+import Data.ByteString.Builder (Builder, toLazyByteString)
20+import Data.ByteString (ByteString)
2021
2122import qualified Web.Cookie as Cookie
2223
2324main :: IO ()
2425main = hspec spec
2526
27+toByteString :: Builder -> ByteString
28+toByteString = L8.toStrict . toLazyByteString
29+
2630spec :: Spec
2731spec = do
2832 describe "setPath" $ do
wai-extra/wai-extra.cabal+4−7
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 3.0.22.0
2+Version: 3.0.22.1
33Synopsis: Provides some basic WAI handlers and middleware.
44description:
55 Provides basic WAI handler and middleware functionality:
@@ -88,20 +88,19 @@ flag build-example
8888
8989Library
9090 Build-Depends: base >= 4.6 && < 5
91− , bytestring >= 0.9.1.4
91+ , bytestring >= 0.10.2
9292 , wai >= 3.0.3.0 && < 3.3
9393 , old-locale >= 1.0.0.2 && < 1.1
9494 , time >= 1.1.4
9595 , network >= 2.6.1.0
9696 , directory >= 1.0.1
9797 , transformers >= 0.2.2
98− , blaze-builder >= 0.2.1.4 && < 0.5
9998 , http-types >= 0.7
10099 , text >= 0.7
101100 , case-insensitive >= 0.2
102101 , data-default-class
103102 , fast-logger >= 2.4.5 && < 2.5
104− , wai-logger >= 2.2.6 && < 2.4
103+ , wai-logger >= 2.3.2 && < 2.4
105104 , ansi-terminal
106105 , resourcet >= 0.4.6 && < 1.3
107106 , void >= 0.5
@@ -111,7 +110,7 @@ Library
111110 , word8
112111 , lifted-base >= 0.1.2
113112 , deepseq
114− , streaming-commons
113+ , streaming-commons >= 0.2
115114 , unix-compat
116115 , cookie
117116 , vault
@@ -171,7 +170,6 @@ executable example
171170 , wai
172171 , time
173172 , http-types
174− , blaze-builder
175173 else
176174 buildable: False
177175 default-language: Haskell2010
@@ -200,7 +198,6 @@ test-suite spec
200198 , resourcet
201199 , bytestring
202200 , HUnit
203− , blaze-builder
204201 , cookie
205202 , time
206203 , case-insensitive