@@ -108,18 +108,22 @@ frameSender ctx@Context{outputQ,connectionWindow}
108108 sendResponse strm s h aux lim
109109 loop
110110 switch (OTrailers strm []) = do
111− let flag = setEndStream defaultFlags
112− fillFrameHeader FrameData 0 (streamNumber strm) flag connWriteBuffer
113− closed strm Finished
114− flushN frameHeaderLength
111+ unlessClosed conn strm $ do
112+ -- An empty data frame should be used to end the stream instead
113+ -- when there are no trailers.
114+ let flag = setEndStream defaultFlags
115+ fillFrameHeader FrameData 0 (streamNumber strm) flag connWriteBuffer
116+ closed strm Finished
117+ flushN frameHeaderLength
115118 loop
116119 switch (OTrailers strm trailers) = do
117− -- Trailers always indicate the end of a stream; send them in
118− -- consecutive header+continuation frames and end the stream.
119− builder <- hpackEncodeCIHeaders ctx trailers
120− off <- headerContinue (streamNumber strm) builder True
121− closed strm Finished
122− flushN $ off + frameHeaderLength
120+ unlessClosed conn strm $ do
121+ -- Trailers always indicate the end of a stream; send them in
122+ -- consecutive header+continuation frames and end the stream.
123+ builder <- hpackEncodeCIHeaders ctx trailers
124+ off <- headerContinue (streamNumber strm) builder True
125+ closed strm Finished
126+ flushN $ off + frameHeaderLength
123127 loop
124128
125129 -- Send the response headers and as much of the response as is immediately