Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate request config #141

Merged
merged 2 commits into from
Aug 28, 2024
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 README.org
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ file logging system, and worker functions for non-HTTP-related tasks.
:cider-nrepl true ; If your editor supports CIDER middleware
:mode "dev" ; or prod
:log-dir "logs" ; or "" for stdout
:truncate-request? false ; true by default
:handler product-ns.routing/handler
:workers {:scheduler {:start product-ns.jobs/start-scheduled-jobs!
:stop product-ns.jobs/stop-scheduled-jobs!}}
Expand Down
1 change: 1 addition & 0 deletions src/triangulum/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
(s/def ::url-or-file-path (s/and string? #(re-matches #"^(https?:\/\/[^\s\/$.?#].[^\s]*)|(/[^:*?\"<>|]*)$" %)))
(s/def ::path (s/and string? #(re-matches #"[./][^:*?\"<>|]*" %)))
(s/def ::hostname (s/and string? #(re-matches #"[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" %)))
(s/def ::boolean boolean?)

;; Config file

Expand Down
7 changes: 5 additions & 2 deletions src/triangulum/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
wrap-frame-options
wrap-xss-protection]]
[triangulum.config :as config :refer [get-config]]
[triangulum.logging :refer [log-str]]
[triangulum.logging :refer [log log-str]]
[triangulum.errors :refer [nil-on-error]]
[triangulum.utils :refer [resolve-foreign-symbol]]
[triangulum.response :refer [forbidden-response data-response]]))
Expand Down Expand Up @@ -87,8 +87,11 @@
(let [{:keys [uri request-method params]} request
private-request-keys (or (get-config :server :private-request-keys)
#{:password :passwordConfirmation})
truncate-request? (if (some? (get-config :server :truncate-request?))
(get-config :server :truncate-request?)
true)
param-str (pr-str (apply dissoc params private-request-keys))]
(log-str "Request(" (name request-method) "): \"" uri "\" " param-str)
(log (apply str "Request(" (name request-method) "): \"" uri "\" " param-str) :truncate? truncate-request?)
(handler request))))

(defn wrap-response-logging
Expand Down
2 changes: 1 addition & 1 deletion src/triangulum/logging.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Synchronously create a log entry. Logs will got to standard out as default.
A log file location can be specified with set-log-path!.

Default options are {:newline? true :pprint? false :force-stdout? false}"
Default options are {:newline? true :pprint? false :force-stdout? false truncate? true}"
[data & {:keys [newline? pprint? force-stdout? truncate?]
:or {newline? true pprint? false force-stdout? false truncate? true}}]
(let [timestamp (.format (SimpleDateFormat. "MM/dd HH:mm:ss") (Date.))
Expand Down
7 changes: 5 additions & 2 deletions src/triangulum/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
(s/def ::cider-nrepl boolean?)
(s/def ::mode (s/and ::config/string #{"dev" "prod"}))
(s/def ::log-dir ::config/string)
(s/def ::truncate-request? ::config/boolean)
(s/def ::handler ::config/namespaced-symbol)
(s/def ::keystore-file ::config/string)
(s/def ::keystore-type ::config/string)
Expand All @@ -44,13 +45,14 @@
(defn start-server!
"See README.org -> Web Framework -> triangulum.server for details."
[{:keys [http-port https-port nrepl cider-nrepl nrepl-bind nrepl-port mode log-dir
handler workers keystore-file keystore-type keystore-password]
truncate-request? handler workers keystore-file keystore-type keystore-password]
:or {nrepl-bind "127.0.0.1"
nrepl-port 5555
keystore-file "./.key/keystore.pkcs12"
keystore-type "pkcs12"
keystore-password "foobar"
log-dir ""
truncate-request? true
mode "prod"}}]
(let [has-key? (and keystore-file (.exists (io/file keystore-file)))
ssl? (and has-key? https-port)
Expand All @@ -59,7 +61,8 @@
(create-handler-stack ssl? reload?))
config (merge
{:port http-port
:join? false}
:join? false
:truncate-request? truncate-request?}
(when ssl?
{:ssl? true
:ssl-port https-port
Expand Down
Loading