Skip to content

Instantly share code, notes, and snippets.

@lucasdicioccio
Created August 10, 2017 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasdicioccio/852f6c7d069d272e64d89b9a51d73c04 to your computer and use it in GitHub Desktop.
Save lucasdicioccio/852f6c7d069d272e64d89b9a51d73c04 to your computer and use it in GitHub Desktop.
user@vm051:~/wai$ git diff
diff --git a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
index 3000baa..7bd8604 100644
--- a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
+++ b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
@@ -165,26 +165,29 @@ frameReceiver ctx mkreq recvN = loop 0 `E.catch` sendGoaway
Nothing
| isResponse streamId -> return Nothing
| otherwise -> do
- when (ftyp `notElem` [FrameHeaders,FramePriority]) $
+ when (ftyp `notElem` [FrameHeaders,FramePriority,FrameWindowUpdate]) $
E.throwIO $ ConnectionError ProtocolError "this frame is not allowed in an idel stream"
csid <- readIORef clientStreamId
- if streamId <= csid then do
- if ftyp == FramePriority then
- return Nothing -- will be ignored
- else
- E.throwIO $ ConnectionError ProtocolError "stream identifier must not decrease"
- else do
- when (ftyp == FrameHeaders) $ do
- writeIORef clientStreamId streamId
- cnt <- readIORef concurrency
- -- Checking the limitation of concurrency
- when (cnt >= maxConcurrency) $
- E.throwIO $ StreamError RefusedStream streamId
- ws <- initialWindowSize <$> readIORef http2settings
- newstrm <- newStream streamId (fromIntegral ws)
- when (ftyp == FrameHeaders) $ opened ctx newstrm
- insert streamTable streamId newstrm
- return $ Just newstrm
+ case csid - streamId of
+ lag | lag < 0 -> do
+ when (ftyp == FrameHeaders) $ do
+ writeIORef clientStreamId streamId
+ cnt <- readIORef concurrency
+ -- Checking the limitation of concurrency
+ when (cnt >= maxConcurrency) $
+ E.throwIO $ StreamError RefusedStream streamId
+ ws <- initialWindowSize <$> readIORef http2settings
+ newstrm <- newStream streamId (fromIntegral ws)
+ when (ftyp == FrameHeaders) $ opened ctx newstrm
+ insert streamTable streamId newstrm
+ return $ Just newstrm
+ | lag < 100 -> do
+ return Nothing -- will be ignored
+ | otherwise -> do
+ if ftyp == FramePriority then
+ return Nothing -- will be ignored
+ else
+ E.throwIO $ ConnectionError ProtocolError "stream identifier must not decrease"
consume = void . recvN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment