-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
util.clj
27 lines (22 loc) · 978 Bytes
/
util.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns metabase.middleware.util
"Ring middleware utility functions."
(:require [clojure.string :as str]))
(def response-unauthentic "Generic `401 (Unauthenticated)` Ring response map." {:status 401, :body "Unauthenticated"})
(def response-forbidden "Generic `403 (Forbidden)` Ring response map." {:status 403, :body "Forbidden"})
(defn api-call?
"Is this ring request an API call (does path start with `/api`)?"
[{:keys [^String uri]}]
(str/starts-with? uri "/api"))
(defn public?
"Is this ring request one that will serve `public.html`?"
[{:keys [uri]}]
(re-matches #"^/public/.*$" uri))
(defn embed?
"Is this ring request one that will serve `public.html`?"
[{:keys [uri]}]
(re-matches #"^/embed/.*$" uri))
(defn cacheable?
"Can the ring request be permanently cached?"
[{:keys [uri query-string]}]
;; match requests that are js/css and have a cache-busting query string
(and query-string (re-matches #"^/app/dist/.*\.(js|css)$" uri)))