on master help sign in
Support writing out trailers in 'frameSender'
b068ab3Andrew Pritchard
warp/Network/Wai/Handler/Warp/HTTP2/Sender.hs+14
@@ -140,6 +140,20 @@ frameSender ctx@Context{outputQ,connectionWindow}
140 fillDataHeaderSend strm 0 datPayloadLen mnext
140 fillDataHeaderSend strm 0 datPayloadLen mnext
141 maybeEnqueueNext strm mnext
141 maybeEnqueueNext strm mnext
142 loop
142 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
143
157
144 -- Flush the connection buffer to the socket, where the first 'n' bytes of
158 -- Flush the connection buffer to the socket, where the first 'n' bytes of
145 -- the buffer are filled.
159 -- the buffer are filled.
warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+9
@@ -18,6 +18,7 @@ import Data.IntMap.Strict (IntMap, IntMap)
18import qualified Data.IntMap.Strict as M
18import qualified Data.IntMap.Strict as M
19import qualified Network.HTTP.Types as H
19import qualified Network.HTTP.Types as H
20import Network.Wai (Request, Response)
20import Network.Wai (Request, Response)
21+import Network.Wai.HTTP2 (Trailers)
21import Network.Wai.Handler.Warp.IORef
22import Network.Wai.Handler.Warp.IORef
22import Network.Wai.Handler.Warp.Types
23import Network.Wai.Handler.Warp.Types
23
24
@@ -60,10 +61,18 @@ type BytesFilled = Int
60data Next = Next BytesFilled (Control DynaNext)
61data Next = Next BytesFilled (Control DynaNext)
61
62
62data Output = OFinish
63data Output = OFinish
64+ -- ^ Terminate the connection.
63 | OGoaway ByteString
65 | OGoaway ByteString
66+ -- ^ Send a goaway frame and terminate the connection.
64 | OFrame ByteString
67 | OFrame ByteString
68+ -- ^ Send an entire pre-encoded frame.
65 | OResponse Stream Response Aux
69 | OResponse Stream Response Aux
70+ -- ^ Send the headers and as much of the response as is immediately
71+ -- available.
66 | ONext Stream DynaNext
72 | 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.
67
76
68outputStream :: Output -> Stream
77outputStream :: Output -> Stream
69outputStream (OResponse strm _ _) = strm
78outputStream (OResponse strm _ _) = strm