[web-devel] Upgrading to warp 2

Bardur Arantsson spam at scientician.net
Mon Feb 24 21:00:07 UTC 2014


Hi all,

So I decided to upgrade one of my programs to Warp 2.x, but I'm getting
stuck on generating the Response from a "sourceFileRange" (from
Data.Conduit.Binary).

Here's a snippet of the relevant code:

    serveFile :: Integer -> [(Maybe Integer, Maybe Integer)] -> IO Response
    serveFile fsz [(l,h)] = do
      let l' = maybe 0 id l
      let h' = maybe (fsz-1) id h
      let n = (h' - l' + 1)
      let src = mapOutput (Chunk . fromByteString) $ sourceFileRange sfp
(Just l') (Just n)
      return $ responseSource partialContent206
                         [ hdrContentLength n
                         , (hContentType, mimeType)
                         , hdrContentRange l' h' fsz
                         , hdrAcceptRangesBytes
                         , hdrConnectionClose
                         ] src

When I try this I get:

  src/Handlers.hs:96:54:
    No instance for (MonadResource IO)
      arising from a use of `sourceFileRange'
    Possible fix: add an instance declaration for (MonadResource IO)
    In the second argument of `($)', namely
      `sourceFileRange sfp (Just l') (Just n)'
    In the expression:
      mapOutput (Chunk . fromByteString)
      $ sourceFileRange sfp (Just l') (Just n)
    In an equation for `src':
        src
          = mapOutput (Chunk . fromByteString)
            $ sourceFileRange sfp (Just l') (Just n)

... which I guess kinda makes sense -- you'd need a ResourceT (or
similar) in the monad stack. I'm just not sure how or where to introduce
the ResourceT to get this working.

If I introduce an explicit type signature for "src",

   src :: forall m . MonadResource m => Source m (Flush Builder)

then that line compiles, but I get the equivalent error at the usage
site of "src" in the third argument to "responseSource" (which again
also makes sense).

Anyone got any pointers?

Regards,



More information about the web-devel mailing list