on master help sign in
Support writing out trailers in 'frameSender'
commitb068ab359998b583ecf166708705d15378903581 authorAndrew Pritchard <awpr@google.com> dateFri 24 Jul 2015, 23:21 (11 years ago) parenta94efed
2 files changed+23
warp/Network/Wai/Handler/Warp/HTTP2/Sender.hs+14 warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+9
warp/Network/Wai/Handler/Warp/HTTP2/Sender.hs+14
@@ -140,6 +140,20 @@ frameSender ctx@Context{outputQ,connectionWindow}
140140 fillDataHeaderSend strm 0 datPayloadLen mnext
141141 maybeEnqueueNext strm mnext
142142 loop
143+ switch (OTrailers strm []) _ = do
144+ let flag = setEndStream defaultFlags
145+ fillFrameHeader FrameData 0 (streamNumber strm) flag connWriteBuffer
146+ closed ctx strm Finished
147+ flushN frameHeaderLength
148+ loop
149+ switch (OTrailers strm trailers) _ = do
150+ -- Trailers always indicate the end of a stream; send them in
151+ -- consecutive header+continuation frames and end the stream.
152+ builder <- hpackEncodeTrailers ctx trailers
153+ off <- headerContinue (streamNumber strm) builder True
154+ closed ctx strm Finished
155+ flushN $ off + frameHeaderLength
156+ loop
143157
144158 -- Flush the connection buffer to the socket, where the first 'n' bytes of
145159 -- the buffer are filled.
warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+9
@@ -18,6 +18,7 @@ import Data.IntMap.Strict (IntMap, IntMap)
1818import qualified Data.IntMap.Strict as M
1919import qualified Network.HTTP.Types as H
2020import Network.Wai (Request, Response)
21+import Network.Wai.HTTP2 (Trailers)
2122import Network.Wai.Handler.Warp.IORef
2223import Network.Wai.Handler.Warp.Types
2324
@@ -60,10 +61,18 @@ type BytesFilled = Int
6061data Next = Next BytesFilled (Control DynaNext)
6162
6263data Output = OFinish
64+ -- ^ Terminate the connection.
6365 | OGoaway ByteString
66+ -- ^ Send a goaway frame and terminate the connection.
6467 | OFrame ByteString
68+ -- ^ Send an entire pre-encoded frame.
6569 | OResponse Stream Response Aux
70+ -- ^ Send the headers and as much of the response as is immediately
71+ -- available.
6672 | ONext Stream DynaNext
73+ -- ^ Send a chunk of the response.
74+ | OTrailers Stream Trailers
75+ -- ^ Send a series of trailers in header and continuation frames.
6776
6877outputStream :: Output -> Stream
6978outputStream (OResponse strm _ _) = strm