Skip to content

Commit 51f828a

Browse files
committed
Mark final chunk as final
Closes #109. Depends on kazu-yamamoto/http-semantics#1.
1 parent b054a70 commit 51f828a

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Network/HTTP2/H2/Receiver.hs

+15-15
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ processState (Open _ (NoBody tbl@(_, reqvt))) ctx@Context{..} strm@Stream{stream
180180
streamId
181181
"no body but content-length is not zero"
182182
tlr <- newIORef Nothing
183-
let inpObj = InpObj tbl (Just 0) (return "") tlr
183+
let inpObj = InpObj tbl (Just 0) (return (mempty, True)) tlr
184184
if isServer ctx
185185
then do
186186
let si = toServerInfo roleInfo
@@ -441,7 +441,7 @@ stream FrameHeaders header@FrameHeader{flags, streamId} bs ctx (Open _ (Body q _
441441
then do
442442
tbl <- hpackDecodeTrailer frag streamId ctx
443443
writeIORef tlr (Just tbl)
444-
atomically $ writeTQueue q $ Right ""
444+
atomically $ writeTQueue q $ Right (mempty, True)
445445
return HalfClosedRemote
446446
else -- we don't support continuation here.
447447
E.throwIO $
@@ -486,7 +486,7 @@ stream
486486
E.throwIO $ ConnectionErrorIsSent EnhanceYourCalm streamId "too many empty data"
487487
else do
488488
writeIORef bodyLength len
489-
atomically $ writeTQueue q $ Right body
489+
atomically $ writeTQueue q $ Right (body, endOfStream)
490490
if endOfStream
491491
then do
492492
case mcl of
@@ -499,7 +499,7 @@ stream
499499
streamId
500500
"actual body length is not the same as content-length"
501501
-- no trailers
502-
atomically $ writeTQueue q $ Right ""
502+
atomically $ writeTQueue q $ Right (mempty, True)
503503
return HalfClosedRemote
504504
else return s
505505

@@ -615,26 +615,26 @@ stream x FrameHeader{streamId} _ _ _ _ =
615615
data Source
616616
= Source
617617
(Int -> IO ())
618-
(TQueue (Either E.SomeException ByteString))
618+
(TQueue (Either E.SomeException (ByteString, Bool)))
619619
(IORef ByteString)
620620
(IORef Bool)
621621

622622
mkSource
623-
:: TQueue (Either E.SomeException ByteString) -> (Int -> IO ()) -> IO Source
623+
:: TQueue (Either E.SomeException (ByteString, Bool)) -> (Int -> IO ()) -> IO Source
624624
mkSource q inform = Source inform q <$> newIORef "" <*> newIORef False
625625

626-
readSource :: Source -> IO ByteString
626+
readSource :: Source -> IO (ByteString, Bool)
627627
readSource (Source inform q refBS refEOF) = do
628628
eof <- readIORef refEOF
629629
if eof
630-
then return ""
630+
then return (mempty, True)
631631
else do
632-
bs <- readBS
632+
(bs, isEOF) <- readBS
633633
let len = BS.length bs
634634
inform len
635-
return bs
635+
return (bs, isEOF)
636636
where
637-
readBS :: IO ByteString
637+
readBS :: IO (ByteString, Bool)
638638
readBS = do
639639
bs0 <- readIORef refBS
640640
if bs0 == ""
@@ -644,9 +644,9 @@ readSource (Source inform q refBS refEOF) = do
644644
Left err -> do
645645
writeIORef refEOF True
646646
E.throwIO err
647-
Right bs -> do
648-
when (bs == "") $ writeIORef refEOF True
649-
return bs
647+
Right (bs, isEOF) -> do
648+
writeIORef refEOF isEOF
649+
return (bs, isEOF)
650650
else do
651651
writeIORef refBS ""
652-
return bs0
652+
return (bs0, False)

Network/HTTP2/H2/Stream.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ closeAllStreams ovar evar mErr' = do
8585
mErr
8686
case st of
8787
Open _ (Body q _ _ _) ->
88-
atomically $ writeTQueue q $ maybe (Right mempty) Left mErr
88+
atomically $ writeTQueue q $ maybe (Right (mempty, True)) Left mErr
8989
_otherwise ->
9090
return ()
9191
mErr :: Maybe SomeException

Network/HTTP2/H2/Types.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ data OpenState
109109
| NoBody TokenHeaderTable
110110
| HasBody TokenHeaderTable
111111
| Body
112-
(TQueue (Either SomeException ByteString))
112+
(TQueue (Either SomeException (ByteString, Bool)))
113113
(Maybe Int) -- received Content-Length
114114
-- compared the body length for error checking
115115
(IORef Int) -- actual body length

0 commit comments

Comments
 (0)