Skip to content

Commit

Permalink
Better support for setting header table size to 0
Browse files Browse the repository at this point in the history
The workaround introduced by #17 makes a server use a default table size
when creating response headers, even if the client requested size 0.

This has the consequence that header entries are incorrectly added to
the table, and can therefore be referenced by successive responses,
causing the client to fail parsing the response.

This patch simply skips adding an entry to the table if it doesn't fit.
  • Loading branch information
pcapriotti committed Jun 9, 2021
1 parent 68aec59 commit 598c1bb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Network/HPACK/Table/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ newDynamicTable maxsiz info = do

-- | Renewing 'DynamicTable' with necessary entries copied.
renewDynamicTable :: Size -> DynamicTable -> IO ()
renewDynamicTable 0 _ = return () -- FIXME: handle case 'Max table size = 0'.
renewDynamicTable maxsiz dyntbl@DynamicTable{..} = do
renew <- shouldRenew dyntbl maxsiz
when renew $ do
Expand Down Expand Up @@ -309,14 +308,17 @@ insertFront e DynamicTable{..} = do
table <- readIORef circularTable
let i = off
dsize' = dsize + entrySize e
off' <- adj maxN (off - 1)
unsafeWrite table i e
writeIORef offset off'
writeIORef numOfEntries $ n + 1
writeIORef dynamicTableSize dsize'
case codeInfo of
EncodeInfo rev _ -> insertRevIndex e (DIndex i) rev
_ -> return ()
if maxN == 0
then return ()
else do
off' <- adj maxN (off - 1)
unsafeWrite table i e
writeIORef offset off'
writeIORef numOfEntries $ n + 1
writeIORef dynamicTableSize dsize'
case codeInfo of
EncodeInfo rev _ -> insertRevIndex e (DIndex i) rev
_ -> return ()

adjustTableSize :: DynamicTable -> IO [Entry]
adjustTableSize dyntbl@DynamicTable{..} = adjust []
Expand Down

0 comments on commit 598c1bb

Please sign in to comment.