X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource.hs;h=298b9b2541edd0f4d3d8b170bccb6cc9965bfe4e;hb=ca338174155913a969808d7b20193973394e474e;hp=b7f76f8d986a9849d6c8dea2905a8d7285ea84d8;hpb=2bb7a0baa35dadb5d36d3f9fa98bd242baabc6d1;p=Lucu.git diff --git a/Network/HTTP/Lucu/Resource.hs b/Network/HTTP/Lucu/Resource.hs index b7f76f8..298b9b2 100644 --- a/Network/HTTP/Lucu/Resource.hs +++ b/Network/HTTP/Lucu/Resource.hs @@ -236,9 +236,7 @@ getRemoteCertificate = itrRemoteCert <$> getInteraction -- |Get the 'Request' value which represents the request header. In -- general you don't have to use this action. getRequest ∷ Resource Request -getRequest - = do itr ← getInteraction - liftIO $ atomically $ fromJust <$> readTVar (itrRequest itr) +getRequest = (fromJust ∘ itrRequest) <$> getInteraction -- |Get the 'Method' value of the request. getMethod ∷ Resource Method @@ -608,8 +606,7 @@ input ∷ Int → Resource Lazy.ByteString input limit = do driftTo GettingBody itr ← getInteraction - hasBody ← liftIO $ atomically $ readTVar $ itrRequestHasBody itr - chunk ← if hasBody then + chunk ← if reqHasBody $ fromJust $ itrRequest itr then askForInput itr else do driftTo DecidingHeader @@ -627,13 +624,7 @@ input limit $ fail ("inputLBS: limit must be positive: " ⧺ show actualLimit) -- Reader にリクエスト liftIO $ atomically - $ do chunkLen ← readTVar itrReqChunkLength - writeTVar itrWillReceiveBody True - if ((> actualLimit) <$> chunkLen) ≡ Just True then - -- 受信前から多過ぎる事が分かってゐる - tooLarge actualLimit - else - writeTVar itrReqBodyWanted (Just actualLimit) + $ writeTVar itrReqBodyWanted (Just actualLimit) -- 應答を待つ。トランザクションを分けなければ當然デッドロックする。 chunk ← liftIO $ atomically $ do chunkLen ← readTVar itrReceivedBodyLen @@ -683,27 +674,25 @@ inputChunk ∷ Int → Resource Lazy.ByteString inputChunk limit = do driftTo GettingBody itr ← getInteraction - hasBody ← liftIO $ atomically $ readTVar $ itrRequestHasBody itr - chunk ← if hasBody then - askForInput itr - else - do driftTo DecidingHeader - return (∅) + chunk ← if reqHasBody $ fromJust $ itrRequest itr then + askForInput itr + else + do driftTo DecidingHeader + return (∅) return chunk where askForInput ∷ Interaction → Resource Lazy.ByteString askForInput (Interaction {..}) = do let confLimit = cnfMaxEntityLength itrConfig actualLimit = if limit < 0 then - confLimit - else - limit - when (actualLimit <= 0) + confLimit + else + limit + when (actualLimit ≤ 0) $ fail ("inputChunkLBS: limit must be positive: " ++ show actualLimit) -- Reader にリクエスト liftIO $ atomically - $ do writeTVar itrReqBodyWanted (Just actualLimit) - writeTVar itrWillReceiveBody True + $ writeTVar itrReqBodyWanted (Just actualLimit) -- 應答を待つ。トランザクションを分けなければ當然デッドロック。 chunk ← liftIO $ atomically $ do chunkLen ← readTVar itrReceivedBodyLen @@ -793,15 +782,12 @@ defaultLimit = (-1) -- | Set the response status code. If you omit to compute this action, -- the status code will be defaulted to \"200 OK\". setStatus ∷ StatusCode → Resource () -setStatus code +setStatus sc = do driftTo DecidingHeader itr ← getInteraction - liftIO $ atomically - $ do res ← readTVar $ itrResponse itr - let res' = res { - resStatus = code - } - writeTVar (itrResponse itr) res' + liftIO + $ atomically + $ setResponseStatus itr sc -- | Set a value of given resource header. Comparison of header name -- is case-insensitive. Note that this action is not intended to be @@ -911,7 +897,7 @@ outputChunk wholeChunk unless (Lazy.null wholeChunk) $ liftIO $ atomically $ - writeTVar (itrSentNoBody itr) False + writeTVar (itrSentNoBodySoFar itr) False where sendChunks ∷ Interaction → Lazy.ByteString → Int → Resource () sendChunks itr@(Interaction {..}) str limit @@ -969,7 +955,7 @@ driftTo newState drift itr DecidingHeader _ = postprocess itr drift itr@(Interaction {..}) _ Done - = do bodyIsNull ← readTVar itrSentNoBody + = do bodyIsNull ← readTVar itrSentNoBodySoFar when bodyIsNull $ writeDefaultPage itr drift _ _ _