Skip to content

Commit

Permalink
Add gzip middlewares to spar and proxy (#4013)
Browse files Browse the repository at this point in the history
* Add gunzip middleware to spar

* Add gunzip middleware to proxy
  • Loading branch information
pcapriotti authored Apr 24, 2024
1 parent 2d5073e commit 36cb3bb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelog.d/1-api-changes/gzip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add gzip request support to spar and proxy
2 changes: 2 additions & 0 deletions services/proxy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
, unliftio-core
, uuid
, wai
, wai-middleware-gunzip
, wai-predicates
, wai-routing
, wai-utilities
Expand Down Expand Up @@ -61,6 +62,7 @@ mkDerivation {
unliftio-core
uuid
wai
wai-middleware-gunzip
wai-predicates
wai-routing
wai-utilities
Expand Down
43 changes: 22 additions & 21 deletions services/proxy/proxy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,32 @@ library
-funbox-strict-fields -Wredundant-constraints -Wunused-packages

build-depends:
aeson >=2.0.1.0
, base >=4.6 && <5
, bilge >=0.21
, bytestring >=0.10
, case-insensitive >=1.2
, configurator >=0.3
, exceptions >=0.8
aeson >=2.0.1.0
, base >=4.6 && <5
, bilge >=0.21
, bytestring >=0.10
, case-insensitive >=1.2
, configurator >=0.3
, exceptions >=0.8
, extended
, http-client >=0.7
, http-client-tls >=0.3
, http-reverse-proxy >=0.4
, http-types >=0.9
, http-client >=0.7
, http-client-tls >=0.3
, http-reverse-proxy >=0.4
, http-types >=0.9
, imports
, lens >=4.11
, metrics-wai >=0.5
, retry >=0.7
, text >=1.2
, tinylog >=0.12
, types-common >=0.8
, lens >=4.11
, metrics-wai >=0.5
, retry >=0.7
, text >=1.2
, tinylog >=0.12
, types-common >=0.8
, unliftio-core
, uuid
, wai >=3.2
, wai-predicates >=0.8
, wai-routing >=0.12
, wai-utilities >=0.14.3
, wai >=3.2
, wai-middleware-gunzip
, wai-predicates >=0.8
, wai-routing >=0.12
, wai-utilities >=0.14.3
, wire-api

default-language: GHC2021
Expand Down
2 changes: 2 additions & 0 deletions services/proxy/src/Proxy/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Control.Monad.Catch
import Data.Metrics.Middleware hiding (path)
import Data.Metrics.Middleware.Prometheus (waiPrometheusMiddleware)
import Imports hiding (head)
import Network.Wai.Middleware.Gunzip qualified as GZip
import Network.Wai.Utilities.Server hiding (serverPort)
import Proxy.API (sitemap)
import Proxy.Env
Expand All @@ -43,5 +44,6 @@ run o = do
let middleware =
versionMiddleware (foldMap expandVersionExp (o ^. disabledAPIVersions))
. waiPrometheusMiddleware (sitemap e)
. GZip.gunzip
. catchErrors (e ^. applog) [Right m]
runSettingsWithShutdown s (middleware app) Nothing `finally` destroyEnv e
2 changes: 2 additions & 0 deletions services/spar/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
, vector
, wai
, wai-extra
, wai-middleware-gunzip
, wai-utilities
, warp
, wire-api
Expand Down Expand Up @@ -130,6 +131,7 @@ mkDerivation {
utf8-string
uuid
wai
wai-middleware-gunzip
wai-utilities
warp
wire-api
Expand Down
1 change: 1 addition & 0 deletions services/spar/spar.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ library
, utf8-string
, uuid
, wai
, wai-middleware-gunzip
, wai-utilities
, warp
, wire-api
Expand Down
2 changes: 2 additions & 0 deletions services/spar/src/Spar/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Imports
import Network.Wai (Application)
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Middleware.Gunzip as GZip
import Network.Wai.Utilities.Request (lookupRequestId)
import qualified Network.Wai.Utilities.Server as WU
import qualified SAML2.WebSSO as SAML
Expand Down Expand Up @@ -104,6 +105,7 @@ mkApp sparCtxOpts = do
versionMiddleware (foldMap expandVersionExp (disabledAPIVersions sparCtxOpts))
. WU.heavyDebugLogging heavyLogOnly logLevel sparCtxLogger
. servantPrometheusMiddleware (Proxy @SparAPI)
. GZip.gunzip
. WU.catchErrors sparCtxLogger []
-- Error 'Response's are usually not thrown as exceptions, but logged in
-- 'renderSparErrorWithLogging' before the 'Application' can construct a 'Response'
Expand Down

0 comments on commit 36cb3bb

Please sign in to comment.