### Install Ring-Defaults with deps.edn Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md This snippet shows how to add the ring-defaults library as a dependency in your Clojure project's deps.edn file. ```clojure ring/ring-defaults {:mvn/version "0.7.0"} ``` -------------------------------- ### Install Ring-Defaults with Leiningen Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md This snippet shows how to add the ring-defaults library as a dependency in your Leiningen project's project.clj file. ```clojure [ring/ring-defaults "0.7.0"] ``` -------------------------------- ### Customizing Default Configurations Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md Demonstrates how to customize Ring's default middleware configurations by associating options with the `wrap-defaults` handler. Examples include disabling session support or modifying parameter parsing. ```APIDOC ## Customizing Ring Middleware Defaults The default configurations in Ring are represented as maps of options that can be modified to suit specific needs. For instance, to use the standard site defaults without session support, you can utilize the `assoc` function to override the `:session` key. ### Example: Disabling Session Support ```clojure (wrap-defaults handler (assoc site-defaults :session false)) ``` ### Supported Configuration Keys - `:cookies`: Enables cookie parsing from the request when set to `true`. - `:params`: A map of options for parsing request parameters. - `:keywordize`: Converts parameter keys to keywords if `true`. - `:multipart`: Parses URL-encoded parameters or accepts a map of options for `multipart-params` middleware. - `:nested`: Enables nested parameter parsing via `nested-params` middleware. - `:urlencoded`: Parses URL-encoded parameters from query strings and request bodies. - `:proxy`: Set to `true` if the application operates behind a reverse proxy or load balancer. - `:responses`: A map of options to enhance application responses. - `:absolute-redirects`: Converts relative redirects to absolute URLs. - `:content-length`: Integrates the `content-length` middleware. - `:content-types`: Integrates the `content-type` middleware. - `:default-charset`: Assigns a default charset to text content types. - `:not-modified-responses`: Integrates the `not-modified` middleware. - `:security`: Options for security-related headers and behaviors. - `:anti-forgery`: Enables CSRF protection or accepts options for `ring-anti-forgery`. - `:content-type-options`: Prevents media-type confusion attacks. - `:frame-options`: Protects the site from being framed. - `:hsts`: Enables HTTP Strict Transport Security. - `:ssl-redirect`: Redirects HTTP requests to HTTPS, optionally specifying an `:ssl-port`. - `:xss-protection`: (Deprecated) Enables the X-XSS-Protection header. - `:session`: A map of options for configuring session handling. - `:flash`: Includes the `flash` middleware if `true`. - `:store`: Specifies the Ring session store to use. - `:static`: Configuration for locating static content. - `:files`: Options for the `file` middleware, specifying a `:root` path or other options. - `:resources`: Options for the `resource` middleware, specifying a `:root` path or other options. - `:websocket`: Options for configuring websocket behavior. - `:keepalive`: Enables periodic client pings to maintain connections, or accepts options to set the `:period` in milliseconds. ``` -------------------------------- ### Basic Usage of wrap-defaults Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md Demonstrates the basic usage of the `wrap-defaults` middleware with site defaults. This middleware applies a standard set of Ring middleware based on the provided configuration. ```clojure (require '[ring.middleware.defaults :refer :all]) (def site (wrap-defaults handler site-defaults)) ``` -------------------------------- ### Customize Ring Defaults Without Session Support (Clojure) Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md Demonstrates how to customize the default Ring site configuration to exclude session support. This is achieved by merging a map with the :session key set to false with the existing site-defaults. ```clojure (wrap-defaults handler (assoc site-defaults :session false)) ``` -------------------------------- ### Configure Ring-Defaults for Proxy Source: https://github.com/ring-clojure/ring-defaults/blob/master/README.md Shows how to configure Ring-Defaults when the application is behind a proxy or load balancer. Setting `:proxy` to `true` is crucial for correctly determining the request's URL scheme, especially with SSL redirects. ```clojure (assoc secure-site-defaults :proxy true) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.