Skip to content

Commit a3f7229

Browse files
committed
[fix] fix expected content-types for documentation tarballs
- documentation tarballs produced by cabal haddock are compressed - their mimetype is application/gzip - keeps the applicatoin/x-tar and applicatoin/x-gzip even though there is no tar mimetype and there's now (since 2014) a gzip mimetype, according to RFC6713 - remove the expectUncompressedTarball function as it is now dead code - remove a pair of redundant paren and replace infix `liftM` with <$>
1 parent 962b6d7 commit a3f7229

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/Distribution/Server/Features/Documentation.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Distribution.Server.Framework.BlobStorage (BlobId)
2323
import qualified Distribution.Server.Framework.BlobStorage as BlobStorage
2424
import qualified Distribution.Server.Util.ServeTarball as ServerTarball
2525
import qualified Distribution.Server.Util.DocMeta as DocMeta
26+
import qualified Distribution.Server.Util.GZip as Gzip
2627
import Distribution.Server.Features.BuildReports.BuildReport (PkgDetails(..), BuildStatus(..))
2728
import Data.TarIndex (TarIndex)
2829
import qualified Codec.Archive.Tar as Tar
@@ -46,7 +47,6 @@ import Data.Time.Clock (NominalDiffTime, diffUTCTime, getCurrentTime)
4647
import System.Directory (getModificationTime)
4748
import Control.Applicative
4849
import Distribution.Server.Features.PreferredVersions
49-
import Distribution.Server.Features.PreferredVersions.State (getVersionStatus)
5050
import Distribution.Server.Packages.Types
5151
-- TODO:
5252
-- 1. Write an HTML view for organizing uploads
@@ -327,8 +327,10 @@ documentationFeature name
327327
-- \* Generate the new index
328328
-- \* Drop the index for the old tar-file
329329
-- \* Link the new documentation to the package
330-
fileContents <- expectUncompressedTarball
331-
mres <- liftIO $ BlobStorage.addWith store fileContents
330+
fileContents <- expectCompressedTarball
331+
let filename = display pkgid ++ "-docs" <.> "tar.gz"
332+
unpacked = Gzip.decompressNamed filename fileContents
333+
mres <- liftIO $ BlobStorage.addWith store unpacked
332334
(\content -> return (checkDocTarball pkgid content))
333335
case mres of
334336
Left err -> errBadRequest "Invalid documentation tarball" [MText err]
@@ -377,15 +379,15 @@ documentationFeature name
377379
helper (pkg:pkgs) = do
378380
hasDoc <- queryHasDocumentation (pkgInfoId pkg)
379381
let status = getVersionStatus prefInfo (packageVersion pkg)
380-
if hasDoc && status == NormalVersion
381-
then pure (Just (packageId pkg))
382+
if hasDoc && status == NormalVersion
383+
then pure (Just (packageId pkg))
382384
else helper pkgs
383385

384386
helper2 [] = pure Nothing
385387
helper2 (pkg:pkgs) = do
386388
hasDoc <- queryHasDocumentation (pkgInfoId pkg)
387389
if hasDoc
388-
then pure (Just (packageId pkg))
390+
then pure (Just (packageId pkg))
389391
else helper2 pkgs
390392

391393
withDocumentation :: Resource -> DynamicPath
@@ -400,7 +402,7 @@ documentationFeature name
400402
then (var, unPackageName $ pkgName pkgid)
401403
else e
402404
| e@(var, _) <- dpath ]
403-
basePkgPath = (renderResource' self basedpath)
405+
basePkgPath = renderResource' self basedpath
404406
canonicalLink = show serverBaseURI ++ basePkgPath
405407
canonicalHeader = "<" ++ canonicalLink ++ ">; rel=\"canonical\""
406408

@@ -484,7 +486,7 @@ checkDocTarball pkgid =
484486
------------------------------------------------------------------------------}
485487

486488
mapParaM :: Monad m => (a -> m b) -> [a] -> m [(a, b)]
487-
mapParaM f = mapM (\x -> (,) x `liftM` f x)
489+
mapParaM f = mapM (\x -> (,) x <$> f x)
488490

489491
getFileAge :: FilePath -> IO NominalDiffTime
490492
getFileAge file = diffUTCTime <$> getCurrentTime <*> getModificationTime file

src/Distribution/Server/Framework/RequestContentTypes.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Distribution.Server.Framework.RequestContentTypes (
1919

2020
-- * various specific content types
2121
expectTextPlain,
22-
expectUncompressedTarball,
2322
expectCompressedTarball,
2423
expectAesonContent,
2524
expectCSV,
@@ -102,15 +101,6 @@ gzipDecompress content = go content decompressor
102101
expectTextPlain :: ServerPartE LBS.ByteString
103102
expectTextPlain = expectContentType "text/plain"
104103

105-
-- | Expect an uncompressed @.tar@ file.
106-
--
107-
-- The tar file is not validated.
108-
--
109-
-- A content-encoding of \"gzip\" is handled transparently.
110-
--
111-
expectUncompressedTarball :: ServerPartE LBS.ByteString
112-
expectUncompressedTarball = expectContentType "application/x-tar"
113-
114104
-- | Expect a compressed @.tar.gz@ file.
115105
--
116106
-- Neither the gzip encoding nor the tar format are validated.
@@ -128,7 +118,7 @@ expectCompressedTarball = do
128118
Just actual
129119
| actual == "application/x-tar"
130120
, contentEncoding == Just "gzip" -> consumeRequestBody
131-
| actual == "application/x-gzip"
121+
| actual == "application/gzip" || actual == "application/x-gzip"
132122
, contentEncoding == Nothing -> consumeRequestBody
133123
_ -> errExpectedTarball
134124
where

0 commit comments

Comments
 (0)