, seiResponse ∷ !Response
, seiWillChunkBody ∷ !Bool
- , seiWillDiscardBody ∷ !Bool
, seiWillClose ∷ !Bool
, seiBodyToSend ∷ !Builder
}
, seiResponse = res
, seiWillChunkBody = arWillChunkBody
- , seiWillDiscardBody = arWillDiscardBody
, seiWillClose = arWillClose
, seiBodyToSend = body
}
, niResponse ∷ !(TVar Response)
, niSendContinue ∷ !(TMVar Bool)
, niWillChunkBody ∷ !Bool
- , niWillDiscardBody ∷ !(TVar Bool)
, niWillClose ∷ !(TVar Bool)
, niResponseHasCType ∷ !(TVar Bool)
-- FIXME: use TBChan Builder (in stm-chans package)
response ← newTVarIO $ emptyResponse arInitialStatus
sendContinue ← newEmptyTMVarIO
- willDiscardBody ← newTVarIO arWillDiscardBody
willClose ← newTVarIO arWillClose
responseHasCType ← newTVarIO False
bodyToSend ← newEmptyTMVarIO
, niResponse = response
, niSendContinue = sendContinue
, niWillChunkBody = arWillChunkBody
- , niWillDiscardBody = willDiscardBody
, niWillClose = willClose
, niResponseHasCType = responseHasCType
, niBodyToSend = bodyToSend
postprocessWithRequest ∷ NormalInteraction → STM ()
postprocessWithRequest ni@(NI {..})
- = do willDiscardBody ← readTVar niWillDiscardBody
- canHaveBody ← if willDiscardBody then
- return False
- else
- resCanHaveBody <$> readTVar niResponse
-
- updateRes ni
+ = do updateRes ni
$ deleteHeader "Content-Length"
∘ deleteHeader "Transfer-Encoding"
+ canHaveBody ← resCanHaveBody <$> readTVar niResponse
if canHaveBody then
- do when niWillChunkBody $
- writeHeader ni "Transfer-Encoding" (Just "chunked")
- writeDefaultPageIfNeeded ni
- else
- do writeTVar niWillDiscardBody True
- -- These headers make sense for HEAD requests even
- -- when there won't be a response entity body.
+ do when niWillChunkBody
+ $ writeHeader ni "Transfer-Encoding" (Just "chunked")
when (reqMethod niRequest ≢ HEAD)
- $ updateRes ni
- $ deleteHeader "Content-Type"
- ∘ deleteHeader "Etag"
- ∘ deleteHeader "Last-Modified"
+ $ writeDefaultPageIfNeeded ni
+ else
+ -- These headers make sense for HEAD requests even when
+ -- there won't be a response entity body.
+ when (reqMethod niRequest ≢ HEAD)
+ $ updateRes ni
+ $ deleteHeader "Content-Type"
+ ∘ deleteHeader "Etag"
+ ∘ deleteHeader "Last-Modified"
hasConnClose ← (≡ Just "close") <$> readCIHeader ni "Connection"
willClose ← readTVar niWillClose
arRequest ∷ !Request
, arInitialStatus ∷ !SomeStatusCode
, arWillChunkBody ∷ !Bool
- , arWillDiscardBody ∷ !Bool
, arWillClose ∷ !Bool
, arExpectedContinue ∷ !Bool
, arReqBodyLength ∷ !(Maybe RequestBodyLength)
arRequest = req
, arInitialStatus = fromStatusCode OK
, arWillChunkBody = False
- , arWillDiscardBody = False
, arWillClose = False
, arExpectedContinue = False
, arReqBodyLength = Nothing
= do req ← gets arRequest
case reqMethod req of
GET → return ()
- HEAD → modify $ \ar → ar { arWillDiscardBody = True }
+ HEAD → return ()
POST → return ()
PUT → return ()
DELETE → return ()
import Network.HTTP.Lucu.HandleLike
import Network.HTTP.Lucu.HttpVersion
import Network.HTTP.Lucu.Interaction
+import Network.HTTP.Lucu.Request
import Network.HTTP.Lucu.Response
import Prelude.Unicode
import System.IO (hPutStrLn, stderr)
writeBodyIfNeeded ctx ni@(NI {..})
= join $
atomically $
- do willDiscardBody ← readTVar niWillDiscardBody
- if willDiscardBody then
- return $ discardBody ctx ni
- else
+ do canHaveBody ← resCanHaveBody <$> readTVar niResponse
+ if canHaveBody ∧ reqMethod niRequest ≢ HEAD then
if niWillChunkBody then
return $ writeChunkedBody ctx ni
else
return $ writeNonChunkedBody ctx ni
+ else
+ return $ discardBody ctx ni
discardBody ∷ HandleLike h
⇒ Context h
→ IO ()
writeResponseForSEI ctx@(Context {..}) (SEI {..})
= do hPutBuilder cHandle $ convertSuccessVia ((⊥) ∷ AsciiBuilder) seiResponse
- unless seiWillDiscardBody $
+ when (reqMethod seiRequest ≢ HEAD) $
if seiWillChunkBody then
do hPutBuilder cHandle $ BB.chunkedTransferEncoding seiBodyToSend
hPutBuilder cHandle BB.chunkedTransferTerminator
component: Lucu
release: Lucu-1.0
reporter: PHO <pho@cielonegro.org>
-status: :unstarted
+status: :in_progress
disposition:
creation_time: 2011-12-16 10:11:08.635552 Z
references: []
- PHO <pho@cielonegro.org>
- created
- ""
+- - 2011-12-20 01:22:49.383628 Z
+ - PHO <pho@cielonegro.org>
+ - changed status from unstarted to in_progress
+ - ""
git_branch: