diff --git a/postgrest.cabal b/postgrest.cabal index 25c3bf2e7..69e3746da 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -55,7 +55,6 @@ library PostgREST.Logger PostgREST.Middleware PostgREST.MediaType - PostgREST.OpenAPI PostgREST.Query PostgREST.Query.QueryBuilder PostgREST.Query.SqlFragment @@ -69,6 +68,7 @@ library PostgREST.Request.ReadQuery PostgREST.Request.Types PostgREST.Response + PostgREST.Response.OpenAPI PostgREST.Version PostgREST.Workers other-modules: Paths_postgrest diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 8ff6cc1ea..e191bb9b7 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -167,8 +167,6 @@ postgrestResponse -> Wai.Request -> Handler IO Wai.Response postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer AuthResult{..} req = do - body <- lift $ Wai.strictRequestBody req - dbStructure <- case maybeDbStructure of Just dbStructure -> @@ -176,6 +174,8 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut Nothing -> throwError Error.NoSchemaCacheError + body <- lift $ Wai.strictRequestBody req + apiRequest <- liftEither . mapLeft Error.ApiRequestError $ ApiRequest.userApiRequest conf dbStructure req body @@ -187,7 +187,7 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut else runDbHandler appState (Query.txMode apiRequest) (Just authRole /= configDbAnonRole) configDbPreparedStatements . Middleware.optionalRollback conf apiRequest $ do - Query.runPgLocals conf authClaims authRole apiRequest jsonDbS pgVer + Query.setPgLocals conf authClaims authRole apiRequest jsonDbS pgVer handleRequest (ctx apiRequest) runDbHandler :: AppState.AppState -> SQL.Mode -> Bool -> Bool -> DbHandler b -> Handler IO b diff --git a/src/PostgREST/Query.hs b/src/PostgREST/Query.hs index d3344ec14..063a8a8dd 100644 --- a/src/PostgREST/Query.hs +++ b/src/PostgREST/Query.hs @@ -8,7 +8,7 @@ module PostgREST.Query , singleUpsertQuery , txMode , updateQuery - , runPgLocals + , setPgLocals , DbHandler ) where @@ -228,9 +228,9 @@ failsChangesOffLimits (Just maxChanges) RSStandard{rsQueryTotal=queryTotal} = throwError $ Error.OffLimitsChangesError queryTotal maxChanges -- | Runs local(transaction scoped) GUCs for every request, plus the pre-request function -runPgLocals :: AppConfig -> KM.KeyMap JSON.Value -> Text -> +setPgLocals :: AppConfig -> KM.KeyMap JSON.Value -> Text -> ApiRequest -> ByteString -> PgVersion -> DbHandler () -runPgLocals conf claims role req jsonDbS actualPgVersion = do +setPgLocals conf claims role req jsonDbS actualPgVersion = do lift $ SQL.statement mempty $ SQL.dynamicallyParameterized ("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ appSettingsSql ++ specSql)) HD.noResult (configDbPreparedStatements conf) diff --git a/src/PostgREST/Response.hs b/src/PostgREST/Response.hs index 6af522828..da4b7f524 100644 --- a/src/PostgREST/Response.hs +++ b/src/PostgREST/Response.hs @@ -23,10 +23,10 @@ import qualified Network.HTTP.Types.Status as HTTP import qualified Network.HTTP.Types.URI as HTTP import qualified Network.Wai as Wai -import qualified PostgREST.Error as Error -import qualified PostgREST.MediaType as MediaType -import qualified PostgREST.OpenAPI as OpenAPI -import qualified PostgREST.RangeQuery as RangeQuery +import qualified PostgREST.Error as Error +import qualified PostgREST.MediaType as MediaType +import qualified PostgREST.RangeQuery as RangeQuery +import qualified PostgREST.Response.OpenAPI as OpenAPI import PostgREST.Config (AppConfig (..)) import PostgREST.DbStructure (DbStructure (..)) diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/Response/OpenAPI.hs similarity index 99% rename from src/PostgREST/OpenAPI.hs rename to src/PostgREST/Response/OpenAPI.hs index d6e73d2e9..a2f7cb9ee 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/Response/OpenAPI.hs @@ -4,7 +4,7 @@ Description : Generates the OpenAPI output -} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} -module PostgREST.OpenAPI (encode) where +module PostgREST.Response.OpenAPI (encode) where import qualified Data.Aeson as JSON import qualified Data.ByteString.Char8 as BS