<commit_before>(ns stonecutter.handler
  (:require [ring.middleware.defaults :as ring-mw]
            [ring.util.response :as r]
            [ring.adapter.jetty :as ring-jetty]
            [scenic.routes :as scenic]
            [clojure.tools.logging :as log]
            [stonecutter.view.error :as error]
            [stonecutter.view.view-helpers :as vh]
            [stonecutter.db.storage :as s]
            [stonecutter.helper :as sh]
            [stonecutter.routes :as routes]
            [stonecutter.logging :as log-config]
            [stonecutter.client :as client]
            [stonecutter.controller.user :as user]
            [stonecutter.controller.oauth :as oauth]
            [stonecutter.translation :as t]
            [stonecutter.middleware :as m]
            [stonecutter.db.migration :as migration]
            [stonecutter.db.mongo :as mongo]
            [stonecutter.config :as config])
  (:gen-class))

(def default-context {:translator (t/translations-fn t/translation-map)})

(defn not-found [request]
  (-> (sh/html-response (error/not-found-error default-context))
      (r/status 404)))

(defn err-handler [request]
  (-> (sh/html-response (error/internal-server-error default-context))
      (r/status 500)))

(defn csrf-err-handler [req]
  (-> (sh/html-response (error/csrf-error default-context))
      (r/status 403)))

(def site-handlers
  (->
    {:home                               user/home
     :show-registration-form             user/show-registration-form
     :register-user                      user/register-user
     :show-sign-in-form                  user/show-sign-in-form
     :sign-in                            user/sign-in
     :sign-out                           user/sign-out
     :show-profile                       user/show-profile
     :show-profile-created               user/show-profile-created
     :show-profile-deleted               user/show-profile-deleted
     :show-delete-account-confirmation   user/show-confirm-account-confirmation
     :delete-account                     user/delete-account
     :show-authorise-form                oauth/show-authorise-form
     :authorise                          oauth/authorise
     :authorise-client                   oauth/authorise-client
     :show-authorise-failure             oauth/show-authorise-failure}
    (m/wrap-handlers m/wrap-disable-caching #{:show-sign-in-form :home})
    (m/wrap-handlers m/wrap-signed-in #{:show-registration-form :register-user
                                        :show-sign-in-form      :sign-in
                                        :sign-out
                                        :show-profile-deleted
                                        :authorise})))

(def api-handlers
  {:validate-token         oauth/validate-token})

(defn splitter [site api]
  (fn [request]
    (let [uri (-> request :uri)]
      (if (.startsWith uri "/api")
        (api request)
        (site request)))))

(defn handle-anti-forgery-error [req]
  (log/warn "ANTI_FORGERY_ERROR - headers: " (:headers req))
  (csrf-err-handler req))<commit_msg>RS & AB | 15 | Disable caching with no exceptions<commit_after>(ns stonecutter.handler
  (:require [ring.middleware.defaults :as ring-mw]
            [ring.util.response :as r]
            [ring.adapter.jetty :as ring-jetty]
            [scenic.routes :as scenic]
            [clojure.tools.logging :as log]
            [stonecutter.view.error :as error]
            [stonecutter.view.view-helpers :as vh]
            [stonecutter.db.storage :as s]
            [stonecutter.helper :as sh]
            [stonecutter.routes :as routes]
            [stonecutter.logging :as log-config]
            [stonecutter.client :as client]
            [stonecutter.controller.user :as user]
            [stonecutter.controller.oauth :as oauth]
            [stonecutter.translation :as t]
            [stonecutter.middleware :as m]
            [stonecutter.db.migration :as migration]
            [stonecutter.db.mongo :as mongo]
            [stonecutter.config :as config])
  (:gen-class))

(def default-context {:translator (t/translations-fn t/translation-map)})

(defn not-found [request]
  (-> (sh/html-response (error/not-found-error default-context))
      (r/status 404)))

(defn err-handler [request]
  (-> (sh/html-response (error/internal-server-error default-context))
      (r/status 500)))

(defn csrf-err-handler [req]
  (-> (sh/html-response (error/csrf-error default-context))
      (r/status 403)))

(def site-handlers
  (->
    {:home                               user/home
     :show-registration-form             user/show-registration-form
     :register-user                      user/register-user
     :show-sign-in-form                  user/show-sign-in-form
     :sign-in                            user/sign-in
     :sign-out                           user/sign-out
     :show-profile                       user/show-profile
     :show-profile-created               user/show-profile-created
     :show-profile-deleted               user/show-profile-deleted
     :show-delete-account-confirmation   user/show-confirm-account-confirmation
     :delete-account                     user/delete-account
     :show-authorise-form                oauth/show-authorise-form
     :authorise                          oauth/authorise
     :authorise-client                   oauth/authorise-client
     :show-authorise-failure             oauth/show-authorise-failure}
    (m/wrap-handlers m/wrap-disable-caching #{})
    (m/wrap-handlers m/wrap-signed-in #{:show-registration-form :register-user
                                        :show-sign-in-form      :sign-in
                                        :sign-out
                                        :show-profile-deleted
                                        :authorise})))

(def api-handlers
  {:validate-token         oauth/validate-token})

(defn splitter [site api]
  (fn [request]
    (let [uri (-> request :uri)]
      (if (.startsWith uri "/api")
        (api request)
        (site request)))))

(defn handle-anti-forgery-error [req]
  (log/warn "ANTI_FORGERY_ERROR - headers: " (:headers req))
  (csrf-err-handler req))
{'fraction_non_alphanumeric': 0.11812297734627832, 'fraction_numerical': 0.003236245954692557, 'mean_word_length': 1.6630762602326583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '636691', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1791, 'n_words': 338}