Skip to content

Commit

Permalink
Use Word
Browse files Browse the repository at this point in the history
  • Loading branch information
marinelli committed Dec 13, 2024
1 parent e82dab4 commit 984f98e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions http-client/Network/HTTP/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
managerSetProxy po = managerSetInsecureProxy po . managerSetSecureProxy po

-- @since 0.7.17
managerSetMaxHeaderLength :: Int -> ManagerSettings -> ManagerSettings
managerSetMaxHeaderLength :: Word -> ManagerSettings -> ManagerSettings
managerSetMaxHeaderLength l manager = manager
{ managerMaxHeaderLength = MaxHeaderLength l }

-- @since 0.7.18
managerSetMaxNumberHeaders :: Int -> ManagerSettings -> ManagerSettings
managerSetMaxNumberHeaders l manager = manager
{ managerMaxNumberHeaders = MaxNumberHeaders l }
managerSetMaxNumberHeaders :: Word -> ManagerSettings -> ManagerSettings
managerSetMaxNumberHeaders n manager = manager
{ managerMaxNumberHeaders = MaxNumberHeaders n }

-- $example1
-- = Example Usage
Expand Down
4 changes: 2 additions & 2 deletions http-client/Network/HTTP/Client/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ connectionReadLineWith mhl conn bs0 =
go bs front total =
case S.break (== charLF) bs of
(_, "") -> do
when (total >= unMaxHeaderLength mhl) $ do
when (total >= unMaxHeaderLength mhl && total /= 0) $ do
-- We reached the maximum length for an header field.
throwHttp OverlongHeaders
bs' <- connectionRead conn
when (S.null bs') $ throwHttp IncompleteHeaders
go bs' (front . (bs:)) (total + S.length bs)
go bs' (front . (bs:)) (total + fromIntegral (S.length bs))
(x, S.drop 1 -> y) -> do
unless (S.null y) $! connectionUnread conn y
return $! killCR $! S.concat $! front [x]
Expand Down
8 changes: 4 additions & 4 deletions http-client/Network/HTTP/Client/Headers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ parseStatusHeaders mhl mnh conn timeout' onEarlyHintHeaders cont
Just (i, "") -> Just i
_ -> Nothing

guardMaxNumberHeaders :: Int -> IO ()
guardMaxNumberHeaders :: Word -> IO ()
guardMaxNumberHeaders count =
when (count >= unMaxNumberHeaders mnh) $ do
when (count >= unMaxNumberHeaders mnh && count /= 0) $ do
-- We reached the maximum number of header fields.
throwHttp OverlongHeaders

parseHeaders :: Int -> ([Header] -> [Header]) -> IO [Header]
parseHeaders :: Word -> ([Header] -> [Header]) -> IO [Header]
parseHeaders count front = do
guardMaxNumberHeaders count
line <- connectionReadLine mhl conn
Expand All @@ -112,7 +112,7 @@ parseStatusHeaders mhl mnh conn timeout' onEarlyHintHeaders cont
-- an exception, ignore it for robustness.
parseHeaders count front

parseEarlyHintHeadersUntilFailure :: Int -> ([Header] -> [Header]) -> IO [Header]
parseEarlyHintHeadersUntilFailure :: Word -> ([Header] -> [Header]) -> IO [Header]
parseEarlyHintHeadersUntilFailure count front = do
guardMaxNumberHeaders count
line <- connectionReadLine mhl conn
Expand Down
12 changes: 6 additions & 6 deletions http-client/Network/HTTP/Client/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,14 @@ data ManagerSettings = ManagerSettings
-- Since 0.4.7
, managerMaxHeaderLength :: MaxHeaderLength
-- ^ Configure the maximum size, in bytes, of an HTTP header field.
-- Set it to a negative number to remove this limit (eg: for debugging purposes).
-- Set it to 0 to remove this limit (eg: for debugging purposes).
--
-- Default: 4096
--
-- @since 0.7.17
, managerMaxNumberHeaders :: MaxNumberHeaders
-- ^ Configure the maximum number of HTTP header fields.
-- Set it to a negative number to remove this limit (eg: for debugging purposes).
-- Set it to 0 to remove this limit (eg: for debugging purposes).
--
-- Default: 100
--
Expand Down Expand Up @@ -922,20 +922,20 @@ data StreamFileStatus = StreamFileStatus
--
-- @since 0.7.14
newtype MaxHeaderLength = MaxHeaderLength
{ unMaxHeaderLength :: Int
{ unMaxHeaderLength :: Word
}
deriving (Eq, Show, Ord, Num, T.Typeable)

noMaxHeaderLength :: MaxHeaderLength
noMaxHeaderLength = - 1
noMaxHeaderLength = 0

-- | The maximum number of header fields.
--
-- @since 0.7.18
newtype MaxNumberHeaders = MaxNumberHeaders
{ unMaxNumberHeaders :: Int
{ unMaxNumberHeaders :: Word
}
deriving (Eq, Show, Ord, Num, T.Typeable)

noMaxNumberHeaders :: MaxNumberHeaders
noMaxNumberHeaders = - 1
noMaxNumberHeaders = 0

0 comments on commit 984f98e

Please sign in to comment.