Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Upgrade nginz (#1658)

* Improvements to local integration test setup when using buildah and kind (#1667)
* The servant-swagger dependency now points to the current upstream master (#1656).
* Improved error handling middleware (#1671).
* Refactor function createUser for readability (#1670)

## Federation changes (alpha feature, do not use yet)
Expand Down
14 changes: 7 additions & 7 deletions libs/wai-utilities/src/Network/Wai/Utilities/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,28 @@ rethrow5xx logger app req k = app req k'
if statusCode st < 500
then k resp
else do
rsbody :: LText <- liftIO $ cs <$> lazyResponseBody resp
rsbody <- liftIO (lazyResponseBody resp)
throwM $ wrapError st rsbody

-- | Wrap the body of an HTTP error into a Wai.Error structure.
--
-- If the error is already a JSON serialisation of a Wai.Error, avoid creating
-- an unnecessary wrapper.
wrapError :: Status -> LText -> Wai.Error
wrapError :: Status -> LByteString -> Wai.Error
wrapError st body =
decode (LT.encodeUtf8 body)
?: Wai.mkError st "server-error" body
decode body
?: Wai.mkError st "server-error" (cs body)

-- | This flushes the response! If you want to keep using the response, you need to construct
-- a new one with a fresh body stream.
lazyResponseBody :: Response -> IO LByteString
lazyResponseBody rs = case responseToStream rs of
(_, _, cont :: (StreamingBody -> IO ()) -> IO ()) -> do
tvar <- atomically $ newTVar mempty
let pushstream builder = atomically $ modifyTVar tvar (<> builder)
bref <- newIORef mempty
let pushstream builder = modifyIORef bref (<> builder)
cont $ \streamingBody ->
streamingBody pushstream (pure ())
atomically $ toLazyByteString <$> readTVar tvar
toLazyByteString <$> readIORef bref

--------------------------------------------------------------------------------
-- Utilities
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ mkApp o = do
middleware :: Env -> (RequestId -> Wai.Application) -> Wai.Application
middleware e =
Metrics.servantPlusWAIPrometheusMiddleware (sitemap o) (Proxy @ServantCombinedAPI)
. catchErrors (e ^. applog) [Right $ e ^. metrics]
. GZip.gunzip
. GZip.gzip GZip.def
. catchErrors (e ^. applog) [Right $ e ^. metrics]
. lookupRequestIdMiddleware
app e r k = runHandler e r (Server.route rtree r k) k

Expand Down
2 changes: 1 addition & 1 deletion services/cannon/src/Cannon/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ run o = do
middleware :: Wai.Middleware
middleware =
waiPrometheusMiddleware sitemap
. catchErrors g [Right m]
. Gzip.gzip Gzip.def
. catchErrors g [Right m]
start = middleware app
runSettings s start `finally` do
Async.cancel refreshMetricsThread
Expand Down
2 changes: 1 addition & 1 deletion services/cargohold/src/CargoHold/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ run o = do
middleware :: Env -> Wai.Middleware
middleware e =
waiPrometheusMiddleware sitemap
. catchErrors (e ^. appLogger) [Right $ e ^. metrics]
. GZip.gzip GZip.def
. catchErrors (e ^. appLogger) [Right $ e ^. metrics]
serve e r k = runHandler e r (Server.route rtree r k) k
2 changes: 1 addition & 1 deletion services/galley/src/Galley/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ mkApp o = do
Log.close l
middlewares =
servantPlusWAIPrometheusMiddleware API.sitemap (Proxy @CombinedAPI)
. catchErrors l [Right m]
. GZip.gunzip
. GZip.gzip GZip.def
. catchErrors l [Right m]
return (middlewares $ servantApp e, e, finalizer)
where
rtree = compile API.sitemap
Expand Down
2 changes: 1 addition & 1 deletion services/gundeck/src/Gundeck/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ run o = do
middleware :: Env -> Wai.Middleware
middleware e =
waiPrometheusMiddleware sitemap
. catchErrors (e ^. applog) [Right $ e ^. monitor]
. GZip.gunzip
. GZip.gzip GZip.def
. catchErrors (e ^. applog) [Right $ e ^. monitor]
app :: Env -> Wai.Application
app e r k = runGundeck e r (route routes r k)
routes = compile sitemap