From 24f4aa819807d000772cf67a43fd475bb1623c0e Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao Date: Mon, 10 Aug 2026 15:53:30 +0530 Subject: [PATCH 1/5] fix: remove newline from curl --write-out option in posthttpfile and puthttpfile --- cabal-install/src/Distribution/Client/HttpUtils.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index d2e5f5848d0..3c8c651a710 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -538,7 +538,7 @@ curlTransport prog = , "--form" , "package=@" ++ path , "--write-out" - , "\n%{http_code}" + , "%{http_code}" , "--user-agent" , userAgent , "--silent" @@ -564,7 +564,7 @@ curlTransport prog = , "--data-binary" , "@" ++ path , "--write-out" - , "\n%{http_code}" + , "%{http_code}" , "--user-agent" , userAgent , "--silent" From cb4a8b719f7ddc5db3084eb2e6e8d0817e14a4ae Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao Date: Mon, 10 Aug 2026 16:06:16 +0530 Subject: [PATCH 2/5] test: add unit tests for HttpUtils and document fix for curl chunked-encoding upload failures --- cabal-install/cabal-install.cabal | 1 + cabal-install/tests/UnitTests.hs | 4 ++ .../Distribution/Client/HttpUtils.hs | 66 +++++++++++++++++++ changelog.d/10252.md | 8 +++ 4 files changed, 79 insertions(+) create mode 100644 cabal-install/tests/UnitTests/Distribution/Client/HttpUtils.hs create mode 100644 changelog.d/10252.md diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index f55e4e85108..707bf28ac0f 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -343,6 +343,7 @@ test-suite unit-tests UnitTests.Distribution.Client.FetchUtils UnitTests.Distribution.Client.Get UnitTests.Distribution.Client.Glob + UnitTests.Distribution.Client.HttpUtils UnitTests.Distribution.Client.GZipUtils UnitTests.Distribution.Client.IndexUtils UnitTests.Distribution.Client.IndexUtils.ActiveRepos diff --git a/cabal-install/tests/UnitTests.hs b/cabal-install/tests/UnitTests.hs index 0020c695d12..c38f65d40c1 100644 --- a/cabal-install/tests/UnitTests.hs +++ b/cabal-install/tests/UnitTests.hs @@ -8,6 +8,7 @@ import qualified UnitTests.Distribution.Client.FetchUtils import qualified UnitTests.Distribution.Client.GZipUtils import qualified UnitTests.Distribution.Client.Get import qualified UnitTests.Distribution.Client.Glob +import qualified UnitTests.Distribution.Client.HttpUtils import qualified UnitTests.Distribution.Client.IndexUtils import qualified UnitTests.Distribution.Client.IndexUtils.ActiveRepos import qualified UnitTests.Distribution.Client.IndexUtils.Timestamp @@ -47,6 +48,9 @@ main = do , testGroup "UnitTests.Distribution.Client.Glob" UnitTests.Distribution.Client.Glob.tests + , testGroup + "UnitTests.Distribution.Client.HttpUtils" + UnitTests.Distribution.Client.HttpUtils.tests , testGroup "Distribution.Client.GZipUtils" UnitTests.Distribution.Client.GZipUtils.tests diff --git a/cabal-install/tests/UnitTests/Distribution/Client/HttpUtils.hs b/cabal-install/tests/UnitTests/Distribution/Client/HttpUtils.hs new file mode 100644 index 00000000000..078d4b1e17e --- /dev/null +++ b/cabal-install/tests/UnitTests/Distribution/Client/HttpUtils.hs @@ -0,0 +1,66 @@ +module UnitTests.Distribution.Client.HttpUtils + ( tests + ) where + +import Distribution.Client.Compat.Prelude +import Prelude () + +import Distribution.Client.HttpUtils + ( HttpTransport (..) + , isOldHackageURI + , remoteRepoTryUpgradeToHttps + ) +import Distribution.Client.Types (RemoteRepo (..), RepoName (..)) +import Distribution.Verbosity (Verbosity (..), defaultVerbosityHandles, normal) +import Network.URI (URI, nullURI, parseURI) + +import Test.Tasty +import Test.Tasty.HUnit + +tests :: [TestTree] +tests = + [ testGroup + "isOldHackageURI" + [ testCase "old hackage archive URI" $ + case parseURI "http://hackage.haskell.org/packages/archive" of + Just uri -> assertBool "should be old hackage URI" (isOldHackageURI uri) + Nothing -> assertFailure "failed to parse URI" + , testCase "modern hackage package URI" $ + case parseURI "http://hackage.haskell.org/package/foo" of + Just uri -> assertBool "should not be old hackage URI" (not (isOldHackageURI uri)) + Nothing -> assertFailure "failed to parse URI" + , testCase "non-hackage URI" $ + case parseURI "http://example.com/packages/archive" of + Just uri -> assertBool "should not be old hackage URI" (not (isOldHackageURI uri)) + Nothing -> assertFailure "failed to parse URI" + ] + , testGroup + "remoteRepoTryUpgradeToHttps" + [ testCase "upgrade http to https when supported" $ do + let dummyUri = fromMaybe nullURI (parseURI "http://hackage.haskell.org/") + repo = emptyTestRemoteRepo (RepoName "hackage") dummyUri + dummyTransport = + HttpTransport + { getHttp = \_ _ _ _ _ -> error "unused" + , postHttp = \_ _ _ _ -> error "unused" + , postHttpFile = \_ _ _ _ -> error "unused" + , putHttpFile = \_ _ _ _ _ -> error "unused" + , transportSupportsHttps = True + , transportManuallySelected = False + } + normalVerbosity = Verbosity normal defaultVerbosityHandles + upgraded <- remoteRepoTryUpgradeToHttps normalVerbosity dummyTransport repo + show (remoteRepoURI upgraded) @?= "https://hackage.haskell.org/" + ] + ] + +emptyTestRemoteRepo :: RepoName -> URI -> RemoteRepo +emptyTestRemoteRepo name uri = + RemoteRepo + { remoteRepoName = name + , remoteRepoURI = uri + , remoteRepoSecure = Nothing + , remoteRepoRootKeys = [] + , remoteRepoKeyThreshold = 0 + , remoteRepoShouldTryHttps = True + } diff --git a/changelog.d/10252.md b/changelog.d/10252.md new file mode 100644 index 00000000000..1719a1a0484 --- /dev/null +++ b/changelog.d/10252.md @@ -0,0 +1,8 @@ +--- +synopsis: Fix `curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding` during `cabal upload` +packages: [cabal-install] +prs: 12211 +issues: 10252 +--- + +- Removed the newline character from `--write-out` curl arguments when uploading packages. Newer versions of `curl` misinterpret this newline during chunked-encoding transfers, causing upload failures From a34aa0ce592a73f882e60f08ace7e9f3fc19867d Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao Date: Mon, 10 Aug 2026 16:09:02 +0530 Subject: [PATCH 3/5] chore: update synopsis for cabal upload error fix in changelog --- changelog.d/10252.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/10252.md b/changelog.d/10252.md index 1719a1a0484..da0fd4f9bb3 100644 --- a/changelog.d/10252.md +++ b/changelog.d/10252.md @@ -1,5 +1,5 @@ --- -synopsis: Fix `curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding` during `cabal upload` +synopsis: "Fix cabal upload failure with curl chunked-encoding error" packages: [cabal-install] prs: 12211 issues: 10252 From 37eea88dabb2333d91fcda5a77ce85951901bd5b Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao Date: Mon, 10 Aug 2026 16:38:58 +0530 Subject: [PATCH 4/5] refactor: update HTTP status code extraction to parse the last three characters of the response body --- .../src/Distribution/Client/HttpUtils.hs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index 3c8c651a710..e7e3e45cd64 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -586,21 +586,20 @@ curlTransport prog = (code, err, _etag) <- parseResponse verbosity uri resp "" return (code, err) - -- on success these curl invocations produces an output like "200" - -- and on failure it has the server error response first + -- The --write-out option appends the HTTP status code directly to + -- the response body (e.g. "200"). We extract the last 3 + -- characters as the status code. parseResponse :: Verbosity -> URI -> String -> String -> IO (Int, String, Maybe ETag) parseResponse verbosity uri resp headers = - let codeerr = - case reverse (lines resp) of - (codeLine : rerrLines) -> - case readMaybe (trim codeLine) of - Just i -> - let errstr = mkErrstr rerrLines - in Just (i, errstr) - Nothing -> Nothing - [] -> Nothing - - mkErrstr = unlines . reverse . dropWhile (all isSpace) + let respLen = length resp + codeerr + | respLen >= 3 + , let (body, codeStr) = splitAt (respLen - 3) resp + , Just code <- readMaybe codeStr = + Just (code, mkErrstr body) + | otherwise = Nothing + + mkErrstr = unlines . reverse . dropWhile (all isSpace) . reverse . lines mb_etag :: Maybe ETag mb_etag = From 8f13d09c9cc5d8a8ab86257b5e4c0bbe07b986f5 Mon Sep 17 00:00:00 2001 From: Tushar Adhatrao Date: Mon, 10 Aug 2026 16:42:55 +0530 Subject: [PATCH 5/5] docs: clarify status code extraction logic in HttpUtils curl response parsing --- cabal-install/src/Distribution/Client/HttpUtils.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index e7e3e45cd64..4d23a88ef52 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -586,9 +586,10 @@ curlTransport prog = (code, err, _etag) <- parseResponse verbosity uri resp "" return (code, err) - -- The --write-out option appends the HTTP status code directly to - -- the response body (e.g. "200"). We extract the last 3 - -- characters as the status code. + -- On success these curl invocations produce an output like "200" (or body ending in "200"), + -- and on failure it has the server error response first followed by the HTTP status code. + -- The --write-out option appends the 3-digit HTTP status code directly to + -- the response body (e.g. "200"). We extract the last 3 characters as the status code. parseResponse :: Verbosity -> URI -> String -> String -> IO (Int, String, Maybe ETag) parseResponse verbosity uri resp headers = let respLen = length resp