Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using sendfileWithHeader. #86

Merged
merged 1 commit into from Jun 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions warp/Network/Wai/Handler/Warp.hs
Expand Up @@ -162,7 +162,7 @@ allowInterrupt = unblock $ return ()
data Connection = Connection
{ connSendMany :: [B.ByteString] -> IO ()
, connSendAll :: B.ByteString -> IO ()
, connSendFile :: FilePath -> Integer -> Integer -> IO () -> IO () -- ^ offset, length
, connSendFile :: FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO () -- ^ offset, length
, connClose :: IO ()
, connRecv :: IO B.ByteString
}
Expand All @@ -171,7 +171,7 @@ socketConnection :: Socket -> Connection
socketConnection s = Connection
{ connSendMany = Sock.sendMany s
, connSendAll = Sock.sendAll s
, connSendFile = \fp off len act -> sendfile s fp (PartOfFile off len) act
, connSendFile = \fp off len act hdr -> sendfileWithHeader s fp (PartOfFile off len) act hdr
, connClose = sClose s
, connRecv = Sock.recv s bytesPerRead
}
Expand Down Expand Up @@ -586,13 +586,12 @@ sendResponse th req conn r = sendResponse' r
[("Content-Type", "text/plain")]
"File not found"
Right (lengthyHeaders, cl) -> liftIO $ do
let headers' = headers version s lengthyHeaders
sendHeader $ headers' False
let headers' = L.toChunks . toLazyByteString $ headers version s lengthyHeaders False
T.tickle th
if hasBody s req then do
case mpart of
Nothing -> connSendFile conn fp 0 cl (T.tickle th)
Just part -> connSendFile conn fp (filePartOffset part) (filePartByteCount part) (T.tickle th)
Nothing -> connSendFile conn fp 0 cl (T.tickle th) headers'
Just part -> connSendFile conn fp (filePartOffset part) (filePartByteCount part) (T.tickle th) headers'
T.tickle th
return isPersist
else
Expand Down
2 changes: 1 addition & 1 deletion warp/warp.cabal
Expand Up @@ -26,7 +26,7 @@ Library
, blaze-builder-conduit >= 0.4 && < 0.5
, lifted-base >= 0.1 && < 0.2
, blaze-builder >= 0.2.1.4 && < 0.4
, simple-sendfile >= 0.2.2 && < 0.3
, simple-sendfile >= 0.2.4 && < 0.3
, http-types >= 0.6 && < 0.7
, case-insensitive >= 0.2
, unix-compat >= 0.2
Expand Down