From d5758523f326dabcfcb9e5df484fc46b3314dc0b Mon Sep 17 00:00:00 2001 From: Dan Amoroso Date: Tue, 6 Aug 2019 20:23:52 +0200 Subject: [PATCH] Change raw-media-types to accept a string of comma separated MIME types (#1370) --- CHANGELOG.md | 2 ++ src/PostgREST/Config.hs | 18 ++++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d19f841d..a3bf720fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- #1369, Change `raw-media-types` to accept a string of comma separated MIME types - @Dansvidania + ## [6.0.1] - 2019-07-30 ### Added diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index 73f3d3311..3544a9ce6 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -167,9 +167,9 @@ readOptions = do <*> pure False <*> (fmap (fmap coerceText) <$> C.subassocs "app.settings" C.value) <*> (maybe (Right [JSPKey "role"]) parseRoleClaimKey <$> optValue "role-claim-key") - <*> (maybe ["public"] splitExtraSearchPath <$> optValue "db-extra-search-path") + <*> (maybe ["public"] splitOnCommas <$> optValue "db-extra-search-path") <*> ((\x y -> QualifiedIdentifier x <$> y) <$> dbSchema <*> optString "root-spec") - <*> (fmap encodeUtf8 <$> optionalListOfText "raw-media-types") + <*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types") parseJwtAudience :: C.Key -> C.Parser C.Config (Maybe StringOrURI) parseJwtAudience k = @@ -180,12 +180,6 @@ readOptions = do (Just "") -> pure Nothing aud' -> pure aud' - optionalListOfText :: C.Key -> C.Parser C.Config [Text] - optionalListOfText k = - C.optional k (C.list C.string) >>= \case - Nothing -> pure [] - Just types -> pure types - reqString :: C.Key -> C.Parser C.Config Text reqString k = C.required k C.string @@ -219,9 +213,9 @@ readOptions = do parseRoleClaimKey (C.String s) = pRoleClaimKey s parseRoleClaimKey v = pRoleClaimKey $ show v - splitExtraSearchPath :: C.Value -> [Text] - splitExtraSearchPath (C.String s) = strip <$> splitOn "," s - splitExtraSearchPath _ = [] + splitOnCommas :: C.Value -> [Text] + splitOnCommas (C.String s) = strip <$> splitOn "," s + splitOnCommas _ = [] opts = info (helper <*> pathParser) $ fullDesc @@ -283,7 +277,7 @@ readOptions = do |# root-spec = "stored_proc_name" | |## content types to produce raw output - |# raw-media-types=["image/png","image/jpg"] + |# raw-media-types="image/png, image/jpg" |] pathParser :: Parser FilePath