Skip to content

Commit

Permalink
config: implements server-timing-enabled config
Browse files Browse the repository at this point in the history
  • Loading branch information
develop7 committed Nov 22, 2023
1 parent abcb21c commit ebe57a1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PostgREST/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ handleRequest AuthResult{..} conf appState authenticated prepared pgVer apiReq@A
pgrstResponse :: ServerTimingData -> Response.PgrstResponse -> Wai.Response
pgrstResponse timings (Response.PgrstResponse st hdrs bod) = Wai.responseLBS st (hdrs ++ ([renderServerTimingHeader timings | configDbPlanEnabled conf])) bod

withTiming f = if configDbPlanEnabled conf
withTiming f = if configServerTiming conf
then do
(t, r) <- timeItT f
pure (Just t, r)
Expand Down
2 changes: 2 additions & 0 deletions src/PostgREST/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ data AppConfig = AppConfig
, configServerHost :: Text
, configServerPort :: Int
, configServerTraceHeader :: Maybe (CI.CI BS.ByteString)
, configServerTiming :: Bool
, configServerUnixSocket :: Maybe FilePath
, configServerUnixSocketMode :: FileMode
, configAdminServerPort :: Maybe Int
Expand Down Expand Up @@ -272,6 +273,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
<*> (fromMaybe "!4" <$> optString "server-host")
<*> (fromMaybe 3000 <$> optInt "server-port")
<*> (fmap (CI.mk . encodeUtf8) <$> optString "server-trace-header")
<*> (fromMaybe False <$> optBool "server-timing-enabled")
<*> (fmap T.unpack <$> optString "server-unix-socket")
<*> parseSocketFileMode "server-unix-socket-mode"
<*> optInt "admin-server-port"
Expand Down
1 change: 1 addition & 0 deletions test/spec/SpecHelper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
, configRoleSettings = mempty
, configRoleIsoLvl = mempty
, configInternalSCSleep = Nothing
, configServerTiming = True
}

testCfg :: AppConfig
Expand Down

0 comments on commit ebe57a1

Please sign in to comment.