refactor: rm raw media types unnecessary decoding
Just convert them to MTOther instead
This commit is contained in:
committed by
Steve Chavez
parent
1eda7db0fb
commit
28183a667c
@@ -610,9 +610,9 @@ contentTypeHeaders RequestContext{..} =
|
|||||||
-- than `*`
|
-- than `*`
|
||||||
binaryField :: Monad m => RequestContext -> ReadRequest -> Handler m (Maybe FieldName)
|
binaryField :: Monad m => RequestContext -> ReadRequest -> Handler m (Maybe FieldName)
|
||||||
binaryField RequestContext{..} readReq
|
binaryField RequestContext{..} readReq
|
||||||
| returnsScalar (iTarget ctxApiRequest) && iAcceptMediaType ctxApiRequest `elem` rawMediaTypes ctxConfig =
|
| returnsScalar (iTarget ctxApiRequest) && isRawMediaType =
|
||||||
return $ Just "pgrst_scalar"
|
return $ Just "pgrst_scalar"
|
||||||
| iAcceptMediaType ctxApiRequest `elem` rawMediaTypes ctxConfig =
|
| isRawMediaType =
|
||||||
let
|
let
|
||||||
fldNames = fstFieldNames readReq
|
fldNames = fstFieldNames readReq
|
||||||
fieldName = headMay fldNames
|
fieldName = headMay fldNames
|
||||||
@@ -623,10 +623,8 @@ binaryField RequestContext{..} readReq
|
|||||||
throwError $ Error.BinaryFieldError (iAcceptMediaType ctxApiRequest)
|
throwError $ Error.BinaryFieldError (iAcceptMediaType ctxApiRequest)
|
||||||
| otherwise =
|
| otherwise =
|
||||||
return Nothing
|
return Nothing
|
||||||
|
where
|
||||||
rawMediaTypes :: AppConfig -> [MediaType]
|
isRawMediaType = iAcceptMediaType ctxApiRequest `elem` configRawMediaTypes ctxConfig `union` [MTOctetStream, MTTextPlain, MTTextXML]
|
||||||
rawMediaTypes AppConfig{..} =
|
|
||||||
(MediaType.decodeMediaType <$> configRawMediaTypes) `union` [MTOctetStream, MTTextPlain, MTTextXML]
|
|
||||||
|
|
||||||
profileHeader :: ApiRequest -> Maybe HTTP.Header
|
profileHeader :: ApiRequest -> Maybe HTTP.Header
|
||||||
profileHeader ApiRequest{..} =
|
profileHeader ApiRequest{..} =
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import PostgREST.Config.Proxy (Proxy (..),
|
|||||||
isMalformedProxyUri, toURI)
|
isMalformedProxyUri, toURI)
|
||||||
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier, dumpQi,
|
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier, dumpQi,
|
||||||
toQi)
|
toQi)
|
||||||
|
import PostgREST.MediaType (MediaType (..), toMime)
|
||||||
|
|
||||||
import Protolude hiding (Proxy, toList)
|
import Protolude hiding (Proxy, toList)
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ data AppConfig = AppConfig
|
|||||||
, configLogLevel :: LogLevel
|
, configLogLevel :: LogLevel
|
||||||
, configOpenApiMode :: OpenAPIMode
|
, configOpenApiMode :: OpenAPIMode
|
||||||
, configOpenApiServerProxyUri :: Maybe Text
|
, configOpenApiServerProxyUri :: Maybe Text
|
||||||
, configRawMediaTypes :: [BS.ByteString]
|
, configRawMediaTypes :: [MediaType]
|
||||||
, configServerHost :: Text
|
, configServerHost :: Text
|
||||||
, configServerPort :: Int
|
, configServerPort :: Int
|
||||||
, configServerUnixSocket :: Maybe FilePath
|
, configServerUnixSocket :: Maybe FilePath
|
||||||
@@ -143,7 +144,7 @@ toText conf =
|
|||||||
,("log-level", q . dumpLogLevel . configLogLevel)
|
,("log-level", q . dumpLogLevel . configLogLevel)
|
||||||
,("openapi-mode", q . dumpOpenApiMode . configOpenApiMode)
|
,("openapi-mode", q . dumpOpenApiMode . configOpenApiMode)
|
||||||
,("openapi-server-proxy-uri", q . fromMaybe mempty . configOpenApiServerProxyUri)
|
,("openapi-server-proxy-uri", q . fromMaybe mempty . configOpenApiServerProxyUri)
|
||||||
,("raw-media-types", q . T.decodeUtf8 . BS.intercalate "," . configRawMediaTypes)
|
,("raw-media-types", q . T.decodeUtf8 . BS.intercalate "," . fmap toMime . configRawMediaTypes)
|
||||||
,("server-host", q . configServerHost)
|
,("server-host", q . configServerHost)
|
||||||
,("server-port", show . configServerPort)
|
,("server-port", show . configServerPort)
|
||||||
,("server-unix-socket", q . maybe mempty T.pack . configServerUnixSocket)
|
,("server-unix-socket", q . maybe mempty T.pack . configServerUnixSocket)
|
||||||
@@ -238,7 +239,7 @@ parser optPath env dbSettings =
|
|||||||
<*> parseLogLevel "log-level"
|
<*> parseLogLevel "log-level"
|
||||||
<*> parseOpenAPIMode "openapi-mode"
|
<*> parseOpenAPIMode "openapi-mode"
|
||||||
<*> parseOpenAPIServerProxyURI "openapi-server-proxy-uri"
|
<*> parseOpenAPIServerProxyURI "openapi-server-proxy-uri"
|
||||||
<*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types")
|
<*> (maybe [] (fmap (MTOther . encodeUtf8) . splitOnCommas) <$> optValue "raw-media-types")
|
||||||
<*> (fromMaybe "!4" <$> optString "server-host")
|
<*> (fromMaybe "!4" <$> optString "server-host")
|
||||||
<*> (fromMaybe 3000 <$> optInt "server-port")
|
<*> (fromMaybe 3000 <$> optInt "server-port")
|
||||||
<*> (fmap T.unpack <$> optString "server-unix-socket")
|
<*> (fmap T.unpack <$> optString "server-unix-socket")
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ findAcceptMediaType conf action path accepts =
|
|||||||
requestMediaTypes :: AppConfig -> Action -> Path -> [MediaType]
|
requestMediaTypes :: AppConfig -> Action -> Path -> [MediaType]
|
||||||
requestMediaTypes conf action path =
|
requestMediaTypes conf action path =
|
||||||
case action of
|
case action of
|
||||||
ActionRead _ -> defaultMediaTypes ++ rawMediaTypes conf
|
ActionRead _ -> defaultMediaTypes ++ rawMediaTypes
|
||||||
ActionInvoke _ -> invokeMediaTypes
|
ActionInvoke _ -> invokeMediaTypes
|
||||||
ActionInspect _ -> [MTOpenAPI, MTApplicationJSON]
|
ActionInspect _ -> [MTOpenAPI, MTApplicationJSON]
|
||||||
ActionInfo -> [MTTextCSV]
|
ActionInfo -> [MTTextCSV]
|
||||||
@@ -428,14 +428,11 @@ requestMediaTypes conf action path =
|
|||||||
where
|
where
|
||||||
invokeMediaTypes =
|
invokeMediaTypes =
|
||||||
defaultMediaTypes
|
defaultMediaTypes
|
||||||
++ rawMediaTypes conf
|
++ rawMediaTypes
|
||||||
++ [MTOpenAPI | pIsRootSpec path]
|
++ [MTOpenAPI | pIsRootSpec path]
|
||||||
defaultMediaTypes =
|
defaultMediaTypes =
|
||||||
[MTApplicationJSON, MTSingularJSON, MTGeoJSON, MTTextCSV]
|
[MTApplicationJSON, MTSingularJSON, MTGeoJSON, MTTextCSV]
|
||||||
|
rawMediaTypes = configRawMediaTypes conf `union` [MTOctetStream, MTTextPlain, MTTextXML]
|
||||||
rawMediaTypes :: AppConfig -> [MediaType]
|
|
||||||
rawMediaTypes AppConfig{..} =
|
|
||||||
(MediaType.decodeMediaType <$> configRawMediaTypes) `union` [MTOctetStream, MTTextPlain, MTTextXML]
|
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Search a pg proc by matching name and arguments keys to parameters. Since a function can be overloaded,
|
Search a pg proc by matching name and arguments keys to parameters. Since a function can be overloaded,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import PostgREST.Config (AppConfig (..),
|
|||||||
OpenAPIMode (..),
|
OpenAPIMode (..),
|
||||||
parseSecret)
|
parseSecret)
|
||||||
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..))
|
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..))
|
||||||
|
import PostgREST.MediaType (MediaType (..))
|
||||||
import Protolude hiding (toS)
|
import Protolude hiding (toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
|
|
||||||
@@ -176,7 +177,7 @@ testCfgRootSpec :: AppConfig
|
|||||||
testCfgRootSpec = baseCfg { configDbRootSpec = Just $ QualifiedIdentifier mempty "root"}
|
testCfgRootSpec = baseCfg { configDbRootSpec = Just $ QualifiedIdentifier mempty "root"}
|
||||||
|
|
||||||
testCfgHtmlRawOutput :: AppConfig
|
testCfgHtmlRawOutput :: AppConfig
|
||||||
testCfgHtmlRawOutput = baseCfg { configRawMediaTypes = ["text/html"] }
|
testCfgHtmlRawOutput = baseCfg { configRawMediaTypes = [MTOther "text/html"] }
|
||||||
|
|
||||||
testCfgResponseHeaders :: AppConfig
|
testCfgResponseHeaders :: AppConfig
|
||||||
testCfgResponseHeaders = baseCfg { configDbPreRequest = Just $ QualifiedIdentifier mempty "custom_headers" }
|
testCfgResponseHeaders = baseCfg { configDbPreRequest = Just $ QualifiedIdentifier mempty "custom_headers" }
|
||||||
|
|||||||
Reference in New Issue
Block a user