The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Compile-time asset compression and Brotli compression (#72221)
Romeo Van Snick0d8f11ea7df7
diff --git a/.gitignore b/.gitignoreindex 5075cef65a9..d2f2e7de9bb 100644--- a/.gitignore+++ b/.gitignore@@ -67,6 +67,8 @@ cypress.env.json/plugins/process.yml/reset-password-artifacts+/resources/frontend_client/app/**/*.br+/resources/frontend_client/app/**/*.gz/resources/frontend_client/app/dist//resources/frontend_client/app/locales/resources/frontend_client/app/embed.jsdiff --git a/bun.lock b/bun.lockindex d92090fa4c7..ac377fd7ff7 100644--- a/bun.lock+++ b/bun.lock@@ -281,6 +281,7 @@"chokidar-cli": "^3.0.0","chromatic": "^10.2.0","commander": "^12.1.0",+ "compression-rspack-plugin": "^0.2.0","concurrently": "^8.2.2","cross-env": "^10.1.0","cross-fetch": "^3.1.5",@@ -2521,6 +2522,18 @@"compression": ["[email protected]", "", { "dependencies": { "accepts": "~1.3.5", "bytes": "3.0.0", "compressible": "~2.0.16", "debug": "2.6.9", "on-headers": "~1.0.2", "safe-buffer": "5.1.2", "vary": "~1.1.2" } }, "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ=="],+ "compression-rspack-plugin": ["[email protected]", "", { "dependencies": { "p-limit": "7.3.0", "schema-utils": "4.3.3" }, "optionalDependencies": { "compression-rspack-plugin-darwin-arm64": "0.2.0", "compression-rspack-plugin-darwin-x64": "0.2.0", "compression-rspack-plugin-linux-arm64-gnu": "0.2.0", "compression-rspack-plugin-linux-x64-gnu": "0.2.0", "compression-rspack-plugin-linux-x64-musl": "0.2.0" }, "peerDependencies": { "@rspack/core": ">=1.0.0" } }, "sha512-pigLbhr0+M/vAQti9BzfJInWMhTHbcILdaj9cVJj5PQOSAoXPt7dY3tVNgFK486Rl5TdTvMYJLYqWZptmDGmsg=="],++ "compression-rspack-plugin-darwin-arm64": ["[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-cW0SFa8tIu2d4OzvqtwM87MrXjdDb8MKtxS98o2n7b5sUAn6S8tR+tqGzaU//lt4lScjpuKa65MIvSK6JHs2OA=="],++ "compression-rspack-plugin-darwin-x64": ["[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-J3OCk7lNB+piAmyCID7tHVMV+4DFqnLDnlJKBLKt26rgJtT3wMGg3GfpisoNbCym9TJsGSLMh+ce8sE+FD4g1A=="],++ "compression-rspack-plugin-linux-arm64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-ge1gcVlCDZoSK/rYbZKgsrZo4njTCJNd4P/bGcvJw3IBOrAExkpY+A9hA8Ag6rwf4QyEih6MoRZj6j0GJ7bKdA=="],++ "compression-rspack-plugin-linux-x64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-7Qu+P3dVC1mulVwePCRwZY28dzp5eZoZzKPaCTTKhvA6l8JRdvoXBweS3qOqMCXXexhtMSFnkNA8pUSvwU52oA=="],++ "compression-rspack-plugin-linux-x64-musl": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-H2UwTTUhAJMo92A2bYUkBGtdsMSGaAeWNyijjOPsgah+y/L/qSv9wK3j6WBH2sxPEN+NsSHt4cR+UoPlPEBsoQ=="],+"concat-map": ["[email protected]", "", {}, "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="],"concat-stream": ["[email protected]", "", { "dependencies": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" } }, "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw=="],@@ -2855,7 +2868,7 @@"domhandler": ["[email protected]", "", { "dependencies": { "domelementtype": "^2.3.0" } }, "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w=="],- "dompurify": ["[email protected]", "", { "optionalDependencies": { "@types/trusted-types": "^2.0.7" } }, "sha512-nolgK9JcaUXMSmW+j1yaSvaEaoXYHwWyGJlkoCTghc97KgGDDSnpoU/PlEnw63Ah+TGKFOyY+X5LnxaWbCSfXg=="],+ "dompurify": ["[email protected]", "", { "optionalDependencies": { "@types/trusted-types": "^2.0.7" } }, "sha512-lHeS9SA/IKeIFFyYciHBr2n0v1VMPlSj843HdLOwjb2OxNwdq9Xykxqhk+FE42MzAdHvInbAolSE4mhahPpjXA=="],"domutils": ["[email protected]", "", { "dependencies": { "dom-serializer": "^2.0.0", "domelementtype": "^2.3.0", "domhandler": "^5.0.3" } }, "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw=="],@@ -4173,7 +4186,7 @@"oxlint": ["[email protected]", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.58.0", "@oxlint/binding-android-arm64": "1.58.0", "@oxlint/binding-darwin-arm64": "1.58.0", "@oxlint/binding-darwin-x64": "1.58.0", "@oxlint/binding-freebsd-x64": "1.58.0", "@oxlint/binding-linux-arm-gnueabihf": "1.58.0", "@oxlint/binding-linux-arm-musleabihf": "1.58.0", "@oxlint/binding-linux-arm64-gnu": "1.58.0", "@oxlint/binding-linux-arm64-musl": "1.58.0", "@oxlint/binding-linux-ppc64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-musl": "1.58.0", "@oxlint/binding-linux-s390x-gnu": "1.58.0", "@oxlint/binding-linux-x64-gnu": "1.58.0", "@oxlint/binding-linux-x64-musl": "1.58.0", "@oxlint/binding-openharmony-arm64": "1.58.0", "@oxlint/binding-win32-arm64-msvc": "1.58.0", "@oxlint/binding-win32-ia32-msvc": "1.58.0", "@oxlint/binding-win32-x64-msvc": "1.58.0" }, "peerDependencies": { "oxlint-tsgolint": ">=0.18.0" }, "optionalPeers": ["oxlint-tsgolint"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-t4s9leczDMqlvOSjnbCQe7gtoLkWgBGZ7sBdCJ9EOj5IXFSG/X7OAzK4yuH4iW+4cAYe8kLFbC8tuYMwWZm+Cg=="],- "p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],+ "p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^1.2.1" } }, "sha512-7cIXg/Z0M5WZRblrsOla88S4wAK+zOQQWeBYfV3qJuJXMr+LnbYjaadrFaS0JILfEDPVqHyKnZ1Z/1d6J9VVUw=="],"p-locate": ["[email protected]", "", { "dependencies": { "p-limit": "^3.0.2" } }, "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw=="],@@ -5431,7 +5444,7 @@"yauzl": ["[email protected]", "", { "dependencies": { "buffer-crc32": "~0.2.3", "fd-slicer": "~1.1.0" } }, "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g=="],- "yocto-queue": ["[email protected]", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="],+ "yocto-queue": ["[email protected]", "", {}, "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ=="],"yoctocolors-cjs": ["[email protected]", "", {}, "sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA=="],@@ -6011,6 +6024,8 @@"compressible/mime-db": ["[email protected]", "", {}, "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w=="],+ "compression-rspack-plugin/schema-utils": ["[email protected]", "", { "dependencies": { "@types/json-schema": "^7.0.9", "ajv": "^8.9.0", "ajv-formats": "^2.1.1", "ajv-keywords": "^5.1.0" } }, "sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA=="],+"concat-stream/readable-stream": ["[email protected]", "", { "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", "isarray": "~1.0.0", "process-nextick-args": "~2.0.0", "safe-buffer": "~5.1.1", "string_decoder": "~1.1.1", "util-deprecate": "~1.0.1" } }, "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw=="],"concurrently/supports-color": ["[email protected]", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q=="],@@ -6367,8 +6382,12 @@"jest-changed-files/execa": ["[email protected]", "", { "dependencies": { "cross-spawn": "^7.0.3", "get-stream": "^6.0.0", "human-signals": "^2.1.0", "is-stream": "^2.0.0", "merge-stream": "^2.0.0", "npm-run-path": "^4.0.1", "onetime": "^5.1.2", "signal-exit": "^3.0.3", "strip-final-newline": "^2.0.0" } }, "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg=="],+ "jest-changed-files/p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],+"jest-circus/dedent": ["[email protected]", "", { "peerDependencies": { "babel-plugin-macros": "^3.1.0" }, "optionalPeers": ["babel-plugin-macros"] }, "sha512-9JmrhGZpOlEgOLdQgSm0zxFaYoQon408V1v49aqTWuXENVlnCuY9JBZcXZiCsZQWDjTm5Qf/nIvAy77mXDAjEg=="],+ "jest-circus/p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],+"jest-circus/pretty-format": ["[email protected]", "", { "dependencies": { "@jest/schemas": "30.0.5", "ansi-styles": "^5.2.0", "react-is": "^18.3.1" } }, "sha512-9uBdv/B4EefsuAL+pWqueZyZS2Ba+LxfFeQ9DN14HU4bN8bhaxKdkpjpB6fs9+pSjIBu+FXQHImEg8j/Lw0+vA=="],"jest-circus/slash": ["[email protected]", "", {}, "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q=="],@@ -6407,6 +6426,8 @@"jest-runner/jest-worker": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@ungap/structured-clone": "^1.3.0", "jest-util": "30.2.0", "merge-stream": "^2.0.0", "supports-color": "^8.1.1" } }, "sha512-0Q4Uk8WF7BUwqXHuAjc23vmopWJw5WH7w2tqBoUOZpOjW/ZnR44GXXd1r82RvnmI2GZge3ivrYXk/BE2+VtW2g=="],+ "jest-runner/p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],+"jest-runner/source-map-support": ["[email protected]", "", { "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w=="],"jest-runtime/cjs-module-lexer": ["[email protected]", "", {}, "sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ=="],@@ -6627,6 +6648,8 @@"ora/strip-ansi": ["[email protected]", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="],+ "p-locate/p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],+"param-case/tslib": ["[email protected]", "", {}, "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="],"parse-asn1/safe-buffer": ["[email protected]", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],@@ -7411,6 +7434,12 @@"chrome-launcher/is-wsl/is-docker": ["[email protected]", "", { "bin": { "is-docker": "cli.js" } }, "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="],+ "compression-rspack-plugin/schema-utils/@types/json-schema": ["@types/[email protected]", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],++ "compression-rspack-plugin/schema-utils/ajv-formats": ["[email protected]", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA=="],++ "compression-rspack-plugin/schema-utils/ajv-keywords": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.3" } }, "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw=="],+"concat-stream/readable-stream/isarray": ["[email protected]", "", {}, "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="],"concat-stream/readable-stream/string_decoder": ["[email protected]", "", { "dependencies": { "safe-buffer": "~5.1.0" } }, "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg=="],@@ -7667,6 +7696,10 @@"jest-changed-files/execa/signal-exit": ["[email protected]", "", {}, "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="],+ "jest-changed-files/p-limit/yocto-queue": ["[email protected]", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="],++ "jest-circus/p-limit/yocto-queue": ["[email protected]", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="],+"jest-circus/pretty-format/ansi-styles": ["[email protected]", "", {}, "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA=="],"jest-circus/pretty-format/react-is": ["[email protected]", "", {}, "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg=="],@@ -7711,6 +7744,8 @@"jest-runner/jest-worker/supports-color": ["[email protected]", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q=="],+ "jest-runner/p-limit/yocto-queue": ["[email protected]", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="],+"jest-runner/source-map-support/source-map": ["[email protected]", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],"jest-runtime/glob/jackspeak": ["[email protected]", "", { "dependencies": { "@isaacs/cliui": "^8.0.2" }, "optionalDependencies": { "@pkgjs/parseargs": "^0.11.0" } }, "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw=="],@@ -7905,6 +7940,8 @@"ora/string-width/emoji-regex": ["[email protected]", "", {}, "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw=="],+ "p-locate/p-limit/yocto-queue": ["[email protected]", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="],+"patch-package/open/is-docker": ["[email protected]", "", { "bin": { "is-docker": "cli.js" } }, "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="],"patch-package/open/is-wsl": ["[email protected]", "", { "dependencies": { "is-docker": "^2.0.0" } }, "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww=="],@@ -8281,6 +8318,8 @@"chokidar-cli/yargs/yargs-parser/decamelize": ["[email protected]", "", {}, "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA="],+ "compression-rspack-plugin/schema-utils/ajv-formats/ajv": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", "uri-js": "^4.2.2" } }, "sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw=="],+"css-loader/semver/lru-cache/yallist": ["[email protected]", "", {}, "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="],"deep-equal/call-bind/set-function-length/gopd": ["[email protected]", "", { "dependencies": { "get-intrinsic": "^1.1.3" } }, "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA=="],@@ -8783,6 +8822,8 @@"chokidar-cli/yargs/find-up/locate-path/path-exists": ["[email protected]", "", {}, "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="],+ "compression-rspack-plugin/schema-utils/ajv-formats/ajv/uri-js": ["[email protected]", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g=="],+"detective-typescript/@typescript-eslint/typescript-estree/minimatch/brace-expansion/balanced-match": ["[email protected]", "", { "dependencies": { "jackspeak": "^4.2.3" } }, "sha512-x0K50QvKQ97fdEz2kPehIerj+YTeptKF9hyYkKf6egnwmMWAkADiO0QCzSp0R5xN8FTZgYaBfSaue46Ej62nMg=="],"es-get-iterator/stop-iteration-iterator/internal-slot/side-channel/object-inspect": ["[email protected]", "", {}, "sha512-HQ4J+ic8hKrgIt3mqk6cVOVrW2ozL4KdvHlqpBv9vDYWx9ysAgENAdvy4FoGF+KFdhR7nQTNm5J0ctAeOwn+3g=="],@@ -9023,6 +9064,8 @@"chokidar-cli/yargs/find-up/locate-path/p-locate/p-limit": ["[email protected]", "", { "dependencies": { "p-try": "^2.0.0" } }, "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w=="],+ "compression-rspack-plugin/schema-utils/ajv-formats/ajv/uri-js/punycode": ["[email protected]", "", {}, "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="],+"jest-config/glob/jackspeak/@isaacs/cliui/string-width/emoji-regex": ["[email protected]", "", {}, "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg=="],"jest-config/glob/jackspeak/@isaacs/cliui/string-width/strip-ansi": ["[email protected]", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw=="],diff --git a/frontend/build/shared/rspack/compression.js b/frontend/build/shared/rspack/compression.jsnew file mode 100644index 00000000000..e348866be62--- /dev/null+++ b/frontend/build/shared/rspack/compression.js@@ -0,0 +1,47 @@+const { IS_DEV_MODE } = require("../constants");++const SHOULD_COMPRESS =+ "COMPRESSION" in process.env+ ? process.env.COMPRESSION === "true"+ : !IS_DEV_MODE;++const COMPRESSION_ASSET_TEST = /\.(js|css|svg)$/;++function getCompressionConfig() {+ if (!SHOULD_COMPRESS) {+ return [];+ }++ // load these modules conditionally so storybook doesn't choke on them+ const zlib = require("zlib");+ const {+ CompressionRspackPlugin,+ } = require("./plugins/CompressionRspackPlugin");++ // eslint-disable-next-line no-console+ console.log(`[Compression] Compressing assets`);++ return [+ new CompressionRspackPlugin({+ algorithm: "gzip",+ test: COMPRESSION_ASSET_TEST,+ filename: "[path][base].gz",+ compressionOptions: {+ level: zlib.constants.Z_MAX_LEVEL,+ },+ }),+ new CompressionRspackPlugin({+ algorithm: "brotliCompress",+ test: COMPRESSION_ASSET_TEST,+ filename: "[path][base].br",+ compressionOptions: {+ params: {+ [zlib.constants.BROTLI_PARAM_QUALITY]:+ zlib.constants.BROTLI_MAX_QUALITY,+ },+ },+ }),+ ];+}++module.exports.COMPRESSION_CONFIG = getCompressionConfig();diff --git a/frontend/build/shared/rspack/copy-js-from-tmp-directory-plugin.js b/frontend/build/shared/rspack/copy-js-from-tmp-directory-plugin.jsindex 48aa07a3168..3ccde77fac3 100644--- a/frontend/build/shared/rspack/copy-js-from-tmp-directory-plugin.js+++ b/frontend/build/shared/rspack/copy-js-from-tmp-directory-plugin.js@@ -1,4 +1,4 @@-const fs = require("fs");+const fs = require("fs/promises");const path = require("path");const { IS_DEV_MODE } = require("../constants");@@ -6,35 +6,38 @@ const { IS_DEV_MODE } = require("../constants");const PLUGIN_NAME = "copy-js-from-tmp-directory-plugin";module.exports.CopyJsFromTmpDirectoryPlugin = ({- fileName,tmpPath,outputPath,- copySourceMap,cleanupInDevMode,}) => ({name: PLUGIN_NAME,apply(compiler) {- compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => {- const tmpFilePath = path.join(tmpPath, fileName);- const outputFilePath = path.join(outputPath, fileName);+ compiler.hooks.afterEmit.tapPromise(PLUGIN_NAME, async () => {+ const fileNames = await readdir(tmpPath);- // copy embedding-sdk.js from the temp directory to the resources directory- fs.mkdirSync(tmpPath, { recursive: true });- fs.copyFileSync(tmpFilePath, outputFilePath);+ // create the output directory if it doesn't exist.+ await fs.mkdir(outputPath, { recursive: true });- if (copySourceMap) {- const tmpSourceMapPath = `${tmpFilePath}.map`;- const outputSourceMapPath = `${outputFilePath}.map`;-- if (fs.existsSync(tmpSourceMapPath)) {- fs.copyFileSync(tmpSourceMapPath, outputSourceMapPath);- }- }+ await Promise.all(+ fileNames.map((fileName) => {+ const tmpFilePath = path.join(tmpPath, fileName);+ const outputFilePath = path.join(outputPath, fileName);+ return fs.copyFile(tmpFilePath, outputFilePath);+ }),+ );if (!IS_DEV_MODE || cleanupInDevMode) {// cleanup the temp directory to prevent bloat.- fs.rmSync(tmpPath, { recursive: true });+ await fs.rm(tmpPath, { recursive: true, force: true });}});},});++async function readdir(dir) {+ try {+ return await fs.readdir(dir);+ } catch (e) {+ return [];+ }+}diff --git a/frontend/build/shared/rspack/plugins/CompressionRspackPlugin.js b/frontend/build/shared/rspack/plugins/CompressionRspackPlugin.jsnew file mode 100644index 00000000000..87eac44b5e6--- /dev/null+++ b/frontend/build/shared/rspack/plugins/CompressionRspackPlugin.js@@ -0,0 +1,3 @@+// This needs to live in an esm file because the compression-rspack-plugin package+// does not declare commonjs exports.+export { CompressionRspackPlugin } from "compression-rspack-plugin";diff --git a/package.json b/package.jsonindex e19b90e01ba..403ec938f54 100644--- a/package.json+++ b/package.json@@ -286,6 +286,7 @@"chokidar-cli": "^3.0.0","chromatic": "^10.2.0","commander": "^12.1.0",+ "compression-rspack-plugin": "^0.2.0","concurrently": "^8.2.2","cross-env": "^10.1.0","cross-fetch": "^3.1.5",diff --git a/rspack.embedding-sdk-bundle.config.js b/rspack.embedding-sdk-bundle.config.jsindex f9713b8b27e..d8395960c44 100644--- a/rspack.embedding-sdk-bundle.config.js+++ b/rspack.embedding-sdk-bundle.config.js@@ -29,6 +29,9 @@ const {getBannerOptions,} = require("./frontend/build/shared/rspack/get-banner-options");const { SVGO_CONFIG } = require("./frontend/build/shared/rspack/svgo-config");+const {+ COMPRESSION_CONFIG,+} = require("./frontend/build/shared/rspack/compression");const {SDK_BUNDLE_PATH,SDK_BUNDLE_FILENAME,@@ -351,6 +354,7 @@ const config = {analyzerMode: "static",reportFilename: BUILD_PATH + "/dist/report.html",}),+ ...COMPRESSION_CONFIG,].filter(Boolean),};diff --git a/rspack.iframe-sdk-embed.config.js b/rspack.iframe-sdk-embed.config.jsindex a1dfdf708b6..fef707a8b37 100644--- a/rspack.iframe-sdk-embed.config.js+++ b/rspack.iframe-sdk-embed.config.js@@ -7,6 +7,10 @@ const {CopyJsFromTmpDirectoryPlugin,} = require("./frontend/build/shared/rspack/copy-js-from-tmp-directory-plugin");+const {+ COMPRESSION_CONFIG,+} = require("./frontend/build/shared/rspack/compression");+const SRC_PATH = __dirname + "/frontend/src/metabase";const ENTERPRISE_SRC_PATH =__dirname + "/enterprise/frontend/src/metabase-enterprise";@@ -70,11 +74,10 @@ module.exports = {optimization: { splitChunks: false, runtimeChunk: false },devtool: false,plugins: [+ ...COMPRESSION_CONFIG,CopyJsFromTmpDirectoryPlugin({- fileName: OUT_FILE_NAME,tmpPath: OUT_TEMP_PATH,outputPath: path.join(BUILD_PATH, "app/"),- copySourceMap: false,cleanupInDevMode: true,}),],diff --git a/rspack.main.config.js b/rspack.main.config.jsindex 7dd4486ddfa..d11212e6aaf 100644--- a/rspack.main.config.js+++ b/rspack.main.config.js@@ -7,6 +7,9 @@ const rspack = require("@rspack/core");const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");const HtmlWebpackPlugin = require("html-webpack-plugin");const WebpackNotifierPlugin = require("webpack-notifier");+const {+ COMPRESSION_CONFIG,+} = require("./frontend/build/shared/rspack/compression");const {IS_DEV_MODE,@@ -303,6 +306,7 @@ const config = {MB_LOG_ANALYTICS: "false",ENABLE_CLJS_HOT_RELOAD: process.env.ENABLE_CLJS_HOT_RELOAD ?? "false",}),+ ...COMPRESSION_CONFIG,],};diff --git a/src/metabase/server/lib/etag_cache.clj b/src/metabase/server/lib/etag_cache.cljindex fa3c7d53694..4e03907e15e 100644--- a/src/metabase/server/lib/etag_cache.clj+++ b/src/metabase/server/lib/etag_cache.clj@@ -7,8 +7,13 @@(set! *warn-on-reflection* true)-(defn- current-etag-header []- {"ETag" (format "\"%s\"" config/mb-version-hash)})+(defn- format-etag [hash weak?]+ (if weak?+ (format "W/\"%s\"" hash)+ (format "\"%s\"" hash)))++(defn- current-etag-header [weak?]+ {"ETag" (format-etag config/mb-version-hash weak?)})(defn- parse-if-none-match [if-none-match](->> (some-> if-none-match (str/split #"\s*,\s*"))@@ -22,12 +27,28 @@(or (= "*" normalized-if-none-match)(contains? (parse-if-none-match normalized-if-none-match) config/mb-version-hash))))+(def ^:private cacheable-304-headers+ "Headers that a 304 response MUST echo from the corresponding 200 response+ per RFC 9110 §15.4.5. ETag is always set separately."+ #{"Cache-Control" "Content-Location" "Expires" "Vary"})++(defn- carry-over-304-headers+ "Extract cacheable headers from `response` using case-insensitive lookup."+ [response]+ (into {}+ (keep (fn [header-name]+ (when-let [v (response/get-header response header-name)]+ [header-name v])))+ cacheable-304-headers))+(defn with-etag"Return 304 + ETag if If-None-Match matches; else 200 base + ETag."- [response request]+ [response request {weak? :weak?}](if (etag-matches? (get-in request [:headers "if-none-match"]))(-> (response/response "")(response/status 304)- (update :headers merge (current-etag-header)))+ (update :headers merge+ (carry-over-304-headers response)+ (current-etag-header weak?)))(-> response- (update :headers merge (current-etag-header)))))+ (update :headers merge (current-etag-header weak?)))))diff --git a/src/metabase/server/middleware/embedding_sdk_bundle.clj b/src/metabase/server/middleware/embedding_sdk_bundle.cljindex 30ca500ef12..2115c2335d0 100644--- a/src/metabase/server/middleware/embedding_sdk_bundle.clj+++ b/src/metabase/server/middleware/embedding_sdk_bundle.clj@@ -3,61 +3,59 @@(:require[metabase.config.core :as config][metabase.server.lib.etag-cache :as lib.etag-cache]+ [metabase.server.routes.static :as static][ring.util.response :as response]))(set! *warn-on-reflection* true)-(def ^:private bundle-resource "frontend_client/app/embedding-sdk/legacy/embedding-sdk.js")-(def ^:private bootstrap-resource "frontend_client/app/embedding-sdk/chunks/embedding-sdk.js")-(def ^:private content-type "application/javascript; charset=UTF-8")-(def ^:private default-cache-header {"Cache-Control" "public, max-age=60"})-(def ^:private far-future-cache-header {"Cache-Control" "public, max-age=31536000, immutable"})-(def ^:private no-store-cache-header {"Cache-Control" "no-store"})-(def ^:private vary-accept-encoding-header {"Vary" "Accept-Encoding"})+(def ^:private bundle-resource "frontend_client/app/embedding-sdk/legacy/embedding-sdk.js")+(def ^:private bootstrap-resource "frontend_client/app/embedding-sdk/chunks/embedding-sdk.js")++(def ^:private short-cache-header "public, max-age=60")+(def ^:private far-future-cache-header "public, max-age=31536000, immutable")+(def ^:private no-store-cache-header "no-store")(defn- not-found [](-> (response/not-found "Not found")- (update :headers merge no-store-cache-header)))+ (assoc-in [:headers "Cache-Control"] no-store-cache-header)))-(defn- serve-for-dev [base]- (-> base- (response/content-type content-type)- (update :headers merge no-store-cache-header)))+(defn- serve-for-dev+ [request resource]+ (some-> (static/static-resource request resource)+ (assoc-in [:headers "Cache-Control"] no-store-cache-header)))-(defn- serve-for-prod [base request]- (let [resp (lib.etag-cache/with-etag base request)]- (cond-> resp- true (update :headers merge- default-cache-header- vary-accept-encoding-header)- (= 200 (:status resp)) (response/content-type content-type))))+(defn- serve-for-prod+ [request resource]+ (some-> (static/static-resource request resource)+ (lib.etag-cache/with-etag request {:weak? true})+ (assoc-in [:headers "Cache-Control"] short-cache-header)))-(defn- serve-resource-handler- "Serve a JS resource with ETag + 60s caching in prod, no-store in dev."- [resource]- (fn [request]- (let [base (response/resource-response resource)]- (cond- (nil? base) (not-found)- config/is-prod? (serve-for-prod base request)- :else (serve-for-dev base)))))+(defn- serve-chunk+ [request resource]+ (some-> (static/static-resource request resource)+ (assoc-in [:headers "Cache-Control"] far-future-cache-header)))(defn serve-bundle-handler"Serve /app/embedding-sdk.js.When `packageVersion` query param is present and `useLegacyMonolithicBundle`is not `true`, serve the bootstrap entry (chunked loading with parallel auth).Otherwise, serve the legacy monolithic bundle (backward compat for old packages).- Prod: ETag + 60s caching (200/304). Dev: no-store."+ Prod: ETag + 60s caching (200/304).+ Dev: no-store."[](fn [request]- (let [package-version (get-in request [:query-params "packageVersion"])- use-legacy (get-in request [:query-params "useLegacyMonolithicBundle"])+ (let [{{package-version "packageVersion"+ use-legacy "useLegacyMonolithicBundle"} :query-params} requestuse-bootstrap? (and (some? package-version)(not= "true" use-legacy))resource (if use-bootstrap?bootstrap-resource- bundle-resource)]- ((serve-resource-handler resource) request))))+ bundle-resource)+ serve (if config/is-prod?+ serve-for-prod+ serve-for-dev)]+ (or (serve request resource)+ (not-found)))))(defn serve-chunk-handler"Serve /app/embedding-sdk/chunks/:filename — split chunks loaded by the bootstrap.@@ -67,10 +65,6 @@resource-response returns nil for paths containing '..'"[filename](let [resource (str "frontend_client/app/embedding-sdk/chunks/" filename)]- (fn [_request]- (let [base (response/resource-response resource)]- (if (nil? base)- (not-found)- (-> base- (update :headers merge far-future-cache-header vary-accept-encoding-header)- (response/content-type content-type)))))))+ (fn [request]+ (or (serve-chunk request resource)+ (not-found)))))diff --git a/src/metabase/server/routes.clj b/src/metabase/server/routes.cljindex fa4614edab9..93d59184187 100644--- a/src/metabase/server/routes.clj+++ b/src/metabase/server/routes.clj@@ -13,6 +13,7 @@[metabase.server.auth-wrapper :as auth-wrapper][metabase.server.middleware.embedding-sdk-bundle :as mw.embedding-sdk-bundle][metabase.server.routes.index :as index]+ [metabase.server.routes.static :as static][metabase.system.core :as system][metabase.util :as u][metabase.util.log :as log]@@ -77,8 +78,9 @@(GET ["/embedding-sdk/chunks/:filename" :filename #"[^/]+\.js"] [filename :as request]((mw.embedding-sdk-bundle/serve-chunk-handler filename) request))- ;; fall back to serving _all_ other files under /app- (route/resources "/" {:root "frontend_client/app"})+ ;; fall back to serving _all_ other files under /app, preferring+ ;; pre-compressed (.br, .gz) variants when the browser supports them+ (static/precompressed-resources "/" {:root "frontend_client/app"})(route/not-found {:status 404 :body "Not found."}))(mu/defn- api-handler :- ::api.macros/handlerdiff --git a/src/metabase/server/routes/static.clj b/src/metabase/server/routes/static.cljnew file mode 100644index 00000000000..8aef804ea77--- /dev/null+++ b/src/metabase/server/routes/static.clj@@ -0,0 +1,102 @@+(ns metabase.server.routes.static+ "Serves static resources with support for pre-compressed variants (.br, .gz).+ When the browser advertises support for Brotli or gzip via the Accept-Encoding+ header, and a pre-compressed file exists on the classpath, we serve it directly+ instead of compressing on the fly. This avoids CPU overhead at request time+ and lets us use higher compression levels during the build."+ (:require+ [clojure.set :as set]+ [clojure.string :as str]+ [compojure.core :as compojure]+ [ring.util.mime-type :as mime]+ [ring.util.response :as response]))++(def ^:private encoding->extension+ {:gzip ".gz"+ :brotli ".br"+ :identity nil})++(def ^:private encoding->header+ {:gzip "gzip"+ :brotli "br"+ :identity "identity"})++(def ^:private header->encoding+ (into+ {"*" :*}+ (set/map-invert encoding->header)))++(defn- parse-quality+ [str]+ (when-let [[_ q] (re-matches #"(?i)q\s*=\s*(\d+(?:\.\d+)?)" (or str ""))]+ (parse-double q)))++(defn- parse-encoding-part+ [part]+ (let [tokens (str/split (str/trim part) #"\s*;\s*")+ encoding (some-> (first tokens) str/trim header->encoding)+ q-value (or (parse-quality (second tokens)) 1.0)]+ (when encoding+ [encoding q-value])))++(defn- parse-accept-encoding+ "Parses an Accept-Encoding header value into a map of encoding name to quality+ value (a double between 0.0 and 1.0). Encodings without an explicit q parameter+ default to 1.0.++ Example:+ (parse-accept-encoding \"gzip, br;q=1.0, identity;q=0.5\")+ ;; => {\"gzip\" 1.0, \"br\" 1.0, \"identity\" 0.5}"+ [header-value]+ (let [header-value (-> (or header-value "") str/trim)+ parts (str/split header-value #",")]+ (into {:identity 1.0 :* 0.0} (keep parse-encoding-part parts))))++(defn- accepts-encoding?+ "Returns true if the request Accept-Encoding header includes `encoding` with a+ quality value greater than 0."+ [request encoding]+ (let [accepted (-> request+ (response/get-header "accept-encoding")+ parse-accept-encoding)+ quality (or (get accepted encoding)+ (get accepted :*))]+ (pos? quality)))++(defn- compressed-path+ "Returns the path of the pre-compressed artifact for a given encoding."+ [resource-path encoding]+ (str resource-path (encoding->extension encoding)))++(defn- compressed-resource+ "Try to serve a pre-compressed variant of `resource-path`. Returns a Ring+ response map if a compressed variant exists and the client accepts it,+ otherwise nil.++ If encoding is :identity, we don't compress at all and serve the raw resource."+ [request resource-path encoding]+ (when (accepts-encoding? request encoding)+ (some-> (response/resource-response (compressed-path resource-path encoding))+ (response/content-type (mime/ext-mime-type resource-path))+ (assoc-in [:headers "Content-Encoding"] (encoding->header encoding))+ (assoc-in [:headers "Vary"] "Accept-Encoding"))))++(defn static-resource+ "Serve a static resource, preferring pre-compressed variants when available."+ [request resource-path]+ (or (compressed-resource request resource-path :brotli)+ (compressed-resource request resource-path :gzip)+ (compressed-resource request resource-path :identity)))++(defn- add-wildcard [path]+ (str path (if (str/ends-with? path "/") "*" "/*")))++(defn precompressed-resources+ "A Ring handler that serves classpath resources from `root`, preferring+ pre-compressed (.br, .gz) variants when the client supports them.+ Drop-in replacement for `compojure.route/resources`."+ [path {root :root}]+ (compojure/GET (add-wildcard path) request+ (let [{{request-path :*} :route-params} request+ resource-path (str root "/" request-path)]+ (static-resource request resource-path))))diff --git a/test/metabase/metabot/api_test.clj b/test/metabase/metabot/api_test.cljindex 3cdface2113..f90a5bcd358 100644--- a/test/metabase/metabot/api_test.clj+++ b/test/metabase/metabot/api_test.clj@@ -912,6 +912,7 @@(let [captured-args (atom nil)test-metabot-id metabot.config/embedded-metabot-id](with-redefs [metabot.config/check-metabot-enabled! (constantly nil)+ api/check-conversation-access! (constantly nil)api/store-aiservice-messages! (constantly nil)api/native-agent-streaming-request (fn [args](reset! captured-args args)diff --git a/test/metabase/server/lib/etag_cache_test.clj b/test/metabase/server/lib/etag_cache_test.cljindex c41745740b9..47cfda4ec69 100644--- a/test/metabase/server/lib/etag_cache_test.clj+++ b/test/metabase/server/lib/etag_cache_test.clj@@ -16,47 +16,49 @@(deftest with-etag-returns-304-when-etag-matches(testing "Exact strong ETag match returns 304 with only ETag header added"(let [etag (format "\"%s\"" config/mb-version-hash)- resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag}})]- (is (= 304 (:status resp)))- (is (= "" (:body resp)))- (is (= etag (get-in resp [:headers "ETag"])))+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag}} {})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" etag}}+ resp))(is (nil? (get-in resp [:headers "Cache-Control"])))(is (nil? (get-in resp [:headers "Content-Type"])))))- (testing "Weak ETag (W/) is treated as match"+ (testing "Weak ETag (W/) in request is treated as match"(let [etag-weak (format "W/\"%s\"" config/mb-version-hash)- resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag-weak}})]- (is (= 304 (:status resp)))- (is (= "" (:body resp)))- (is (= (format "\"%s\"" config/mb-version-hash)- (get-in resp [:headers "ETag"])))))+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag-weak}} {})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" (format "\"%s\"" config/mb-version-hash)}}+ resp))))(testing "Multiple ETags in If-None-Match; any match triggers 304"(let [header (format "\"other\", W/\"%s\", \"another\"" config/mb-version-hash)- resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" header}})]- (is (= 304 (:status resp)))- (is (= (format "\"%s\"" config/mb-version-hash)- (get-in resp [:headers "ETag"]))))))+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" header}} {})]+ (is (=? {:status 304+ :headers {"ETag" (format "\"%s\"" config/mb-version-hash)}}+ resp)))))(deftest with-etag-returns-200-and-adds-etag-when-no-match- (testing "ETag does not match → 200; adds ETag, preserves existing headers; no Cache-Control/Content-Type"+ (testing "ETag does not match -> 200; adds ETag, preserves existing headers; no Cache-Control/Content-Type"(let [resp (lib.etag-cache/with-etag(base-response {"X-Foo" "bar"})- {:headers {"if-none-match" "\"different\""}})]- (is (= 200 (:status resp)))- (is (= "dummy js" (:body resp)))- (is (= (format "\"%s\"" config/mb-version-hash)- (get-in resp [:headers "ETag"])))- (is (= "bar" (get-in resp [:headers "X-Foo"])))+ {:headers {"if-none-match" "\"different\""}}+ {})]+ (is (=? {:status 200+ :body "dummy js"+ :headers {"ETag" (format "\"%s\"" config/mb-version-hash)+ "X-Foo" "bar"}}+ resp))(is (nil? (get-in resp [:headers "Cache-Control"])))(is (nil? (get-in resp [:headers "Content-Type"])))))- (testing "Missing If-None-Match → 200; adds ETag only"- (let [resp (lib.etag-cache/with-etag (base-response) {:headers {}})]- (is (= 200 (:status resp)))- (is (= "dummy js" (:body resp)))- (is (= (format "\"%s\"" config/mb-version-hash)- (get-in resp [:headers "ETag"])))+ (testing "Missing If-None-Match -> 200; adds ETag only"+ (let [resp (lib.etag-cache/with-etag (base-response) {:headers {}} {})]+ (is (=? {:status 200+ :body "dummy js"+ :headers {"ETag" (format "\"%s\"" config/mb-version-hash)}}+ resp))(is (nil? (get-in resp [:headers "Cache-Control"])))(is (nil? (get-in resp [:headers "Content-Type"]))))))@@ -65,10 +67,131 @@(doseq [if-none-match-value ["*" " * " "* " " *"]](let [resp (lib.etag-cache/with-etag{:status 200 :headers {} :body "dummy js"}- {:headers {"if-none-match" if-none-match-value}})]- (is (= 304 (:status resp)))- (is (= "" (:body resp)))- (is (= (format "\"%s\"" config/mb-version-hash)- (get-in resp [:headers "ETag"])))+ {:headers {"if-none-match" if-none-match-value}}+ {})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" (format "\"%s\"" config/mb-version-hash)}}+ resp))(is (nil? (get-in resp [:headers "Cache-Control"])))(is (nil? (get-in resp [:headers "Content-Type"])))))))++(deftest with-etag-weak-returns-304-when-etag-matches+ (testing "Strong ETag match returns 304 with weak ETag in response"+ (let [etag (format "\"%s\"" config/mb-version-hash)+ weak-etag (format "W/\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag}} {:weak? true})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" weak-etag}}+ resp))))++ (testing "Weak ETag in request matches and response contains weak ETag"+ (let [etag-weak (format "W/\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" etag-weak}} {:weak? true})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" etag-weak}}+ resp))))++ (testing "Multiple ETags in If-None-Match; match triggers 304 with weak ETag in response"+ (let [header (format "\"other\", \"%s\", \"another\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag (base-response) {:headers {"if-none-match" header}} {:weak? true})]+ (is (=? {:status 304+ :headers {"ETag" (format "W/\"%s\"" config/mb-version-hash)}}+ resp)))))++(deftest with-etag-weak-returns-200-and-adds-weak-etag-when-no-match+ (testing "ETag does not match -> 200; adds weak ETag, preserves existing headers"+ (let [resp (lib.etag-cache/with-etag+ (base-response {"X-Foo" "bar"})+ {:headers {"if-none-match" "\"different\""}}+ {:weak? true})]+ (is (=? {:status 200+ :body "dummy js"+ :headers {"ETag" (format "W/\"%s\"" config/mb-version-hash)+ "X-Foo" "bar"}}+ resp))))++ (testing "Missing If-None-Match -> 200; adds weak ETag only"+ (let [resp (lib.etag-cache/with-etag (base-response) {:headers {}} {:weak? true})]+ (is (=? {:status 200+ :body "dummy js"+ :headers {"ETag" (format "W/\"%s\"" config/mb-version-hash)}}+ resp)))))++(deftest with-etag-weak-returns-304-on-wildcard+ (testing "If-None-Match: * returns 304 with weak ETag in response"+ (doseq [if-none-match-value ["*" " * "]]+ (let [resp (lib.etag-cache/with-etag+ {:status 200 :headers {} :body "dummy js"}+ {:headers {"if-none-match" if-none-match-value}}+ {:weak? true})]+ (is (=? {:status 304+ :body ""+ :headers {"ETag" (format "W/\"%s\"" config/mb-version-hash)}}+ resp))))))++(deftest with-etag-304-carries-over-rfc-9110-headers+ (testing "304 echoes Vary, Cache-Control, Content-Location, and Expires from original response"+ (let [original-headers {"Vary" "Accept-Encoding"+ "Cache-Control" "max-age=31536000"+ "Content-Location" "/static/app/main.js"+ "Expires" "Thu, 16 Apr 2026 12:00:00 GMT"}+ etag (format "\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag+ (base-response original-headers)+ {:headers {"if-none-match" etag}}+ {})]+ (is (=? {:status 304+ :body ""+ :headers {"Vary" "Accept-Encoding"+ "Cache-Control" "max-age=31536000"+ "Content-Location" "/static/app/main.js"+ "Expires" "Thu, 16 Apr 2026 12:00:00 GMT"+ "ETag" etag}}+ resp))))++ (testing "304 does NOT carry over non-cacheable headers like Content-Type or X-Custom"+ (let [original-headers {"Content-Type" "application/javascript"+ "X-Custom" "secret"+ "Vary" "Accept-Encoding"}+ etag (format "\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag+ (base-response original-headers)+ {:headers {"if-none-match" etag}}+ {})]+ (is (=? {:status 304+ :headers {"Vary" "Accept-Encoding"}}+ resp))+ (is (nil? (get-in resp [:headers "Content-Type"])))+ (is (nil? (get-in resp [:headers "X-Custom"])))))++ (testing "304 with weak ETag also carries over cacheable headers"+ (let [original-headers {"Vary" "Accept-Encoding" "Cache-Control" "no-cache"}+ etag (format "\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag+ (base-response original-headers)+ {:headers {"if-none-match" etag}}+ {:weak? true})]+ (is (=? {:status 304+ :headers {"Vary" "Accept-Encoding"+ "Cache-Control" "no-cache"+ "ETag" (format "W/\"%s\"" config/mb-version-hash)}}+ resp))))++ (testing "304 carries over headers regardless of case in original response"+ (let [original-headers {"vary" "Accept-Encoding"+ "cache-control" "max-age=600"+ "content-type" "application/javascript"}+ etag (format "\"%s\"" config/mb-version-hash)+ resp (lib.etag-cache/with-etag+ (base-response original-headers)+ {:headers {"if-none-match" etag}}+ {})]+ (is (=? {:status 304+ :headers {"Vary" "Accept-Encoding"+ "Cache-Control" "max-age=600"}}+ resp))+ (is (nil? (get-in resp [:headers "Content-Type"])))+ (is (nil? (get-in resp [:headers "content-type"]))))))diff --git a/test/metabase/server/middleware/embedding_sdk_bundle_test.clj b/test/metabase/server/middleware/embedding_sdk_bundle_test.cljindex e36baef06b6..c7941fa6c17 100644--- a/test/metabase/server/middleware/embedding_sdk_bundle_test.clj+++ b/test/metabase/server/middleware/embedding_sdk_bundle_test.clj@@ -5,19 +5,29 @@[metabase.config.core :as config][metabase.server.lib.etag-cache :as lib.etag-cache][metabase.server.middleware.embedding-sdk-bundle :as mw.embedding-sdk-bundle]+ [metabase.server.routes.static :as static][ring.util.response :as response]))(set! *warn-on-reflection* true)(def ^:private cache-header "public, max-age=60")(def ^:private far-future-cache-header "public, max-age=31536000, immutable")-(def ^:private js-ct "application/javascript; charset=UTF-8")+(def ^:private js-ct "text/javascript")++(defn- fake-static-resource+ "A fake for `static/static-resource` that returns a response with Content-Type+ and Vary headers, mimicking what the real implementation does."+ [_request _resource-path]+ {:status 200+ :headers {"Content-Type" js-ct+ "Vary" "Accept-Encoding"}+ :body "dummy"})(deftest serve-bundle-handler-prod-returns-304-and-adds-cache-header(testing "Prod + ETag match → 304 with Cache-Control, ETag, Vary; no Content-Type"(with-redefs [config/is-prod? true- response/resource-response (constantly {:status 200 :headers {} :body "dummy"})- lib.etag-cache/with-etag (fn [_base _req]+ static/static-resource fake-static-resource+ lib.etag-cache/with-etag (fn [_base _req _opts]{:status 304:headers {"ETag" "\"abc\""}:body ""})]@@ -26,15 +36,13 @@(is (= 304 (:status resp)))(is (= "" (:body resp)))(is (= cache-header (get-in resp [:headers "Cache-Control"])))- (is (= "\"abc\"" (get-in resp [:headers "ETag"])))- (is (= "Accept-Encoding" (get-in resp [:headers "Vary"])))- (is (nil? (get-in resp [:headers "Content-Type"])) "304 should not include Content-Type")))))+ (is (= "\"abc\"" (get-in resp [:headers "ETag"])))))))(deftest serve-bundle-handler-prod-returns-200-and-adds-cache-and-content-type(testing "Prod + ETag miss → 200 with Cache-Control, ETag, Content-Type, Vary"(with-redefs [config/is-prod? true- response/resource-response (constantly {:status 200 :headers {} :body "dummy"})- lib.etag-cache/with-etag (fn [base _req]+ static/static-resource fake-static-resource+ lib.etag-cache/with-etag (fn [base _req _opts](update base :headers assoc "ETag" "\"abc\""))](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)resp (handler {:headers {}})]@@ -46,9 +54,9 @@(is (= "dummy" (:body resp)))))))(deftest serve-bundle-handler-dev-skips-etag-and-sets-no-store- (testing "Dev skips with-etag and sets no-store + Content-Type, no prod-only headers"+ (testing "Dev skips with-etag and sets no-store + Content-Type"(with-redefs [config/is-prod? false- response/resource-response (constantly {:status 200 :headers {} :body "dummy"})+ static/static-resource fake-static-resourcelib.etag-cache/with-etag (fn [& _](throw (ex-info "with-etag should not be called in dev" {})))](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)@@ -56,19 +64,18 @@(is (= 200 (:status resp)))(is (= "no-store" (get-in resp [:headers "Cache-Control"])))(is (= js-ct (get-in resp [:headers "Content-Type"])))- (is (nil? (get-in resp [:headers "Vary"])))+ (is (= "Accept-Encoding" (get-in resp [:headers "Vary"])))(is (= "dummy" (:body resp)))))))(deftest serve-bundle-handler-404-propagates- (testing "Missing resource → 404 with no-store; no prod-only headers"+ (testing "Missing resource → 404 with no-store"(with-redefs [config/is-prod? true- response/resource-response (constantly nil)+ static/static-resource (constantly nil)lib.etag-cache/with-etag (fn [& args] (throw (ex-info "Not expected for 404" {:args args})))](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)resp (handler {:headers {}})](is (= 404 (:status resp)))- (is (= "no-store" (get-in resp [:headers "Cache-Control"])))- (is (nil? (get-in resp [:headers "Vary"])))))))+ (is (= "no-store" (get-in resp [:headers "Cache-Control"])))))));; -- Bundle routing: packageVersion triggers bootstrap, absence → legacy --@@ -76,9 +83,9 @@(testing "No query params (old package) → serves legacy resource"(let [requested-resource (atom nil)](with-redefs [config/is-prod? false- response/resource-response (fn [resource]- (reset! requested-resource resource)- {:status 200 :headers {} :body "legacy-js"})]+ static/static-resource (fn [_request resource]+ (reset! requested-resource resource)+ {:status 200 :headers {} :body "legacy-js"})](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)resp (handler {:headers {}})](is (= 200 (:status resp)))@@ -87,9 +94,9 @@(testing "packageVersion present → serves bootstrap resource"(let [requested-resource (atom nil)](with-redefs [config/is-prod? false- response/resource-response (fn [resource]- (reset! requested-resource resource)- {:status 200 :headers {} :body "bootstrap-js"})]+ static/static-resource (fn [_request resource]+ (reset! requested-resource resource)+ {:status 200 :headers {} :body "bootstrap-js"})](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)resp (handler {:headers {}:query-params {"packageVersion" "0.59.0"}})]@@ -99,9 +106,9 @@(testing "packageVersion + useLegacyMonolithicBundle=true → serves legacy resource"(let [requested-resource (atom nil)](with-redefs [config/is-prod? false- response/resource-response (fn [resource]- (reset! requested-resource resource)- {:status 200 :headers {} :body "legacy-js"})]+ static/static-resource (fn [_request resource]+ (reset! requested-resource resource)+ {:status 200 :headers {} :body "legacy-js"})](let [handler (mw.embedding-sdk-bundle/serve-bundle-handler)resp (handler {:headers {}:query-params {"packageVersion" "0.59.0"@@ -113,7 +120,10 @@(deftest serve-chunk-handler-returns-far-future-cache(testing "Chunk handler always returns far-future cache + Content-Type + Vary"- (with-redefs [response/resource-response (constantly {:status 200 :headers {} :body "chunk-js"})]+ (with-redefs [static/static-resource (constantly {:status 200+ :headers {"Content-Type" js-ct+ "Vary" "Accept-Encoding"}+ :body "chunk-js"})](let [handler (mw.embedding-sdk-bundle/serve-chunk-handler "embedding-sdk-chunk-runtime.a1b2c3d4.js")resp (handler {:headers {}})](is (= 200 (:status resp)))@@ -122,7 +132,7 @@(is (= "Accept-Encoding" (get-in resp [:headers "Vary"]))))))(testing "Missing chunk resource → 404"- (with-redefs [response/resource-response (constantly nil)]+ (with-redefs [static/static-resource (constantly nil)](let [handler (mw.embedding-sdk-bundle/serve-chunk-handler "embedding-sdk-chunk-nonexistent.js")resp (handler {:headers {}})](is (= 404 (:status resp)))diff --git a/test/metabase/server/routes/static_test.clj b/test/metabase/server/routes/static_test.cljnew file mode 100644index 00000000000..afa4cb30e3d--- /dev/null+++ b/test/metabase/server/routes/static_test.clj@@ -0,0 +1,120 @@+(ns metabase.server.routes.static-test+ (:require+ [clojure.test :refer :all]+ [metabase.server.routes.static :as static]))++(deftest ^:parallel parse-accept-encoding-nil-header-test+ (testing "nil header returns identity-only defaults"+ (is (= {:identity 1.0 :* 0.0}+ (#'static/parse-accept-encoding nil)))))++(deftest ^:parallel parse-accept-encoding-simple-test+ (testing "single encoding without q-value defaults to 1.0"+ (is (= {:identity 1.0 :* 0.0 :gzip 1.0}+ (#'static/parse-accept-encoding "gzip")))))++(deftest ^:parallel parse-accept-encoding-multiple-test+ (testing "multiple encodings without q-values"+ (is (= {:identity 1.0 :* 0.0 :gzip 1.0 :brotli 1.0}+ (#'static/parse-accept-encoding "gzip, br")))))++(deftest ^:parallel parse-accept-encoding-with-quality-test+ (testing "encodings with explicit q-values"+ (is (= {:identity 1.0 :* 0.0 :brotli 1.0 :gzip 0.5}+ (#'static/parse-accept-encoding "br, gzip;q=0.5")))))++(deftest ^:parallel parse-accept-encoding-identity-override-test+ (testing "explicit identity q-value overrides the default"+ (is (= {:identity 0.5 :* 0.0 :gzip 1.0}+ (#'static/parse-accept-encoding "gzip, identity;q=0.5")))))++(deftest ^:parallel parse-accept-encoding-wildcard-test+ (testing "wildcard encoding is parsed"+ (is (= {:identity 1.0 :* 0.5 :brotli 1.0}+ (#'static/parse-accept-encoding "br, *;q=0.5")))))++(deftest ^:parallel parse-accept-encoding-zero-quality-test+ (testing "q=0 means encoding is explicitly refused"+ (is (= {:identity 1.0 :* 0.0 :gzip 0.0 :brotli 1.0}+ (#'static/parse-accept-encoding "gzip;q=0, br")))))++(deftest ^:parallel parse-accept-encoding-whitespace-test+ (testing "extra whitespace is tolerated"+ (is (= {:identity 1.0 :* 0.0 :gzip 1.0 :brotli 0.8}+ (#'static/parse-accept-encoding " gzip , br ; q=0.8 ")))))++(deftest ^:parallel parse-accept-encoding-unknown-encoding-test+ (testing "unknown encodings are ignored"+ (is (= {:identity 1.0 :* 0.0 :gzip 1.0}+ (#'static/parse-accept-encoding "gzip, zstd")))))++(defn- request-with-encoding [header-value]+ {:headers {"accept-encoding" header-value}})++(deftest ^:parallel accepts-encoding-basic-test+ (testing "returns true when encoding is listed"+ (is (true? (#'static/accepts-encoding? (request-with-encoding "gzip, br") :brotli)))+ (is (true? (#'static/accepts-encoding? (request-with-encoding "gzip, br") :gzip)))))++(deftest ^:parallel accepts-encoding-refused-test+ (testing "returns false when encoding has q=0"+ (is (false? (#'static/accepts-encoding? (request-with-encoding "gzip;q=0, br") :gzip)))))++(deftest ^:parallel accepts-encoding-wildcard-fallback-test+ (testing "falls back to wildcard when specific encoding not listed"+ (is (true? (#'static/accepts-encoding? (request-with-encoding "*") :brotli)))+ (is (true? (#'static/accepts-encoding? (request-with-encoding "*;q=0.5") :brotli)))))++(deftest ^:parallel accepts-encoding-wildcard-zero-test+ (testing "wildcard q=0 means unlisted encodings are refused"+ (is (false? (#'static/accepts-encoding? (request-with-encoding "gzip, *;q=0") :brotli)))))++(deftest ^:parallel accepts-encoding-no-header-test+ (testing "missing header accepts identity only"+ (is (true? (#'static/accepts-encoding? {} :identity)))+ (is (false? (#'static/accepts-encoding? {} :gzip)))+ (is (false? (#'static/accepts-encoding? {} :brotli)))))++(deftest ^:parallel static-resource-prefers-brotli-test+ (testing "serves brotli when client supports it and .br file exists"+ (let [response (static/static-resource+ (request-with-encoding "gzip, br")+ "static_test/app.js")]+ (is (some? response))+ (is (= "br" (get-in response [:headers "Content-Encoding"])))+ (is (= "text/javascript" (get-in response [:headers "Content-Type"]))))))++(deftest ^:parallel static-resource-falls-back-to-gzip-test+ (testing "serves gzip when client doesn't support brotli"+ (let [response (static/static-resource+ (request-with-encoding "gzip")+ "static_test/app.js")]+ (is (some? response))+ (is (= "gzip" (get-in response [:headers "Content-Encoding"]))))))++(deftest ^:parallel static-resource-falls-back-to-identity-test+ (testing "serves uncompressed when client refuses compressed encodings"+ (let [response (static/static-resource+ (request-with-encoding "gzip;q=0, br;q=0")+ "static_test/app.js")]+ (is (some? response))+ (is (= "identity" (get-in response [:headers "Content-Encoding"]))))))++(deftest ^:parallel static-resource-no-header-test+ (testing "serves uncompressed when no Accept-Encoding header"+ (let [response (static/static-resource {} "static_test/app.js")]+ (is (some? response))+ (is (= "identity" (get-in response [:headers "Content-Encoding"]))))))++(deftest ^:parallel static-resource-missing-file-test+ (testing "returns nil for a resource that doesn't exist"+ (is (nil? (static/static-resource+ (request-with-encoding "gzip, br")+ "static_test/nonexistent.js")))))++(deftest ^:parallel static-resource-sets-vary-header-test+ (testing "response includes Vary: Accept-Encoding"+ (let [response (static/static-resource+ (request-with-encoding "gzip, br")+ "static_test/app.js")]+ (is (= "Accept-Encoding" (get-in response [:headers "Vary"]))))))diff --git a/test_resources/static_test/app.js b/test_resources/static_test/app.jsnew file mode 100644index 00000000000..ce013625030--- /dev/null+++ b/test_resources/static_test/app.js@@ -0,0 +1 @@+hellodiff --git a/test_resources/static_test/app.js.br b/test_resources/static_test/app.js.brnew file mode 100644index 00000000000..093f08f6065--- /dev/null+++ b/test_resources/static_test/app.js.br@@ -0,0 +1 @@+compressed-brdiff --git a/test_resources/static_test/app.js.gz b/test_resources/static_test/app.js.gznew file mode 100644index 00000000000..f6c0605617b--- /dev/null+++ b/test_resources/static_test/app.js.gz@@ -0,0 +1 @@+compressed-gz