[web-devel] ResponseEnumerator

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Tue Dec 13 08:37:24 CET 2011


Hello,

I have a question about WAI. ResponseEnumerator is defined as:

type ResponseEnumerator a = (Status -> ResponseHeaders -> Iteratee Builder IO a) -> IO a

Are there any reasons to use Builder instead of ByteString. 
I could not find code which makes use of Iteratee Builder IO a in Yesod.

Michael posted the following code before. This code converts ByteString
to Builder. But Builder is converted to ByteString in Warp. 

It seems to me that "Iteratee ByteString IO a" is more reasonable than
"Iteratee ByteString IO a". Am I missing something?

--Kazu

----
data Proxy = Proxy

mkYesod "Proxy" [parseRoutes|
/ RootR GET
|]

instance Yesod Proxy where
    approot _ = ""

getRootR :: GHandler Proxy Proxy ()
getRootR = do
    req <- liftIO $ parseUrl "http://www.yesodweb.com/"
    sendWaiResponse $ ResponseEnumerator $ \f -> withManager $ \m ->
        run_ (http req (blaze f) m)

blaze :: (Status -> ResponseHeaders -> Iteratee Builder IO a)
      -> Status -> ResponseHeaders -> Iteratee ByteString IO a
blaze f s h =
    joinI $ EL.map fromByteString $$ f s h'
  where
    h' = filter go h
    go ("Content-Encoding", _) = False
    go _ = True

main :: IO ()
main = warpDebug 3000 Proxy
----



More information about the web-devel mailing list