Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add request.param guc #1710

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/PostgREST/ApiRequest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ data ApiRequest = ApiRequest {
, iMethod :: ByteString -- ^ Raw request method
, iProfile :: Maybe Schema -- ^ The request profile for enabling use of multiple schemas. Follows the spec in hhttps://www.w3.org/TR/dx-prof-conneg/ttps://www.w3.org/TR/dx-prof-conneg/.
, iSchema :: Schema -- ^ The request schema. Can vary depending on iProfile.
, iParams :: [(Text, Text)] -- ^ All request params
}

-- | Examines HTTP request and translates it into user intent.
Expand Down Expand Up @@ -177,6 +178,7 @@ userApiRequest confSchemas rootSpec dbStructure req reqBody
, iMethod = method
, iProfile = profile
, iSchema = schema
, iParams = second (toS . fromMaybe mempty) <$> qParams
}
where
-- queryString with '+' converted to ' '(space)
Expand Down
3 changes: 2 additions & 1 deletion src/PostgREST/Middleware.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ runPgLocals :: AppConfig -> M.HashMap Text JSON.Value ->
ApiRequest -> H.Transaction Response
runPgLocals conf claims app req = do
H.statement mempty $ H.dynamicallyParameterized
("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ appSettingsSql))
("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ paramsSql ++ appSettingsSql))
HD.noResult (configDbPreparedStatements conf)
traverse_ H.sql preReqSql
app req
where
methodSql = setConfigLocal mempty ("request.method", toS $ iMethod req)
pathSql = setConfigLocal mempty ("request.path", toS $ iPath req)
paramsSql = setConfigLocal "request.param." <$> iParams req
headersSql = setConfigLocal "request.header." <$> iHeaders req
cookiesSql = setConfigLocal "request.cookie." <$> iCookies req
claimsWithRole =
Expand Down