diff --git a/http-client/Network/HTTP/Client.hs b/http-client/Network/HTTP/Client.hs index e6a3c7a5..4182ee58 100644 --- a/http-client/Network/HTTP/Client.hs +++ b/http-client/Network/HTTP/Client.hs @@ -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 diff --git a/http-client/Network/HTTP/Client/Connection.hs b/http-client/Network/HTTP/Client/Connection.hs index e846f3ee..99a3502e 100644 --- a/http-client/Network/HTTP/Client/Connection.hs +++ b/http-client/Network/HTTP/Client/Connection.hs @@ -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] diff --git a/http-client/Network/HTTP/Client/Headers.hs b/http-client/Network/HTTP/Client/Headers.hs index 7bb8012a..82badf87 100644 --- a/http-client/Network/HTTP/Client/Headers.hs +++ b/http-client/Network/HTTP/Client/Headers.hs @@ -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 @@ -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 diff --git a/http-client/Network/HTTP/Client/Types.hs b/http-client/Network/HTTP/Client/Types.hs index 71077975..7b740a41 100644 --- a/http-client/Network/HTTP/Client/Types.hs +++ b/http-client/Network/HTTP/Client/Types.hs @@ -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 -- @@ -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