pax_global_header 0000666 0000000 0000000 00000000064 13102426335 0014511 g ustar 00root root 0000000 0000000 52 comment=3c803eb0864d7fbe93ba1595d5d0d6ae09d51eb0
ring-headers-0.3.0/ 0000775 0000000 0000000 00000000000 13102426335 0014061 5 ustar 00root root 0000000 0000000 ring-headers-0.3.0/.gitignore 0000664 0000000 0000000 00000000133 13102426335 0016046 0 ustar 00root root 0000000 0000000 /target
/classes
/checkouts
/codox
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
ring-headers-0.3.0/.travis.yml 0000664 0000000 0000000 00000000050 13102426335 0016165 0 ustar 00root root 0000000 0000000 language: clojure
script: lein test-all
ring-headers-0.3.0/README.md 0000664 0000000 0000000 00000000761 13102426335 0015344 0 ustar 00root root 0000000 0000000 # Ring-Headers
[](https://travis-ci.org/ring-clojure/ring-headers)
Ring middleware for adding and manipulating common response headers.
## Installation
Add the following dependency to your `project.clj`:
[ring/ring-headers "0.3.0"]
## Documentation
* [API Docs](http://ring-clojure.github.io/ring-headers)
## License
Copyright © 2017 James Reeves
Distributed under the MIT License, the same as Ring.
ring-headers-0.3.0/project.clj 0000664 0000000 0000000 00000001462 13102426335 0016224 0 ustar 00root root 0000000 0000000 (defproject ring/ring-headers "0.3.0"
:description "Ring middleware for common response headers"
:url "https://github.com/ring-clojure/ring-headers"
:license {:name "The MIT License"
:url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.5.1"]
[ring/ring-core "1.6.0"]]
:plugins [[lein-codox "0.10.3"]]
:codox {:project {:name "Ring-Headers"}
:output-path "codox"}
:aliases {"test-all" ["with-profile" "default:+1.6:+1.7:+1.8:+1.9" "test"]}
:profiles
{:dev {:dependencies [[ring/ring-mock "0.3.0"]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha10"]]}})
ring-headers-0.3.0/src/ 0000775 0000000 0000000 00000000000 13102426335 0014650 5 ustar 00root root 0000000 0000000 ring-headers-0.3.0/src/ring/ 0000775 0000000 0000000 00000000000 13102426335 0015607 5 ustar 00root root 0000000 0000000 ring-headers-0.3.0/src/ring/middleware/ 0000775 0000000 0000000 00000000000 13102426335 0017724 5 ustar 00root root 0000000 0000000 ring-headers-0.3.0/src/ring/middleware/absolute_redirects.clj 0000664 0000000 0000000 00000003301 13102426335 0024275 0 ustar 00root root 0000000 0000000 (ns ring.middleware.absolute-redirects
"Middleware for replacing relative redirects with absolute redirects. Useful
for clients that do not yet implement RFC 7231 (RFC 2616 does not allow
relative redirects)."
(:require [ring.util.request :as req])
(:import [java.net URL MalformedURLException]))
(defn- redirect? [response]
(#{201 301 302 303 307} (:status response)))
(defn- get-header-key [response ^String header-name]
(->> response :headers keys
(filter #(.equalsIgnoreCase header-name %))
first))
(defn- update-header [response header f & args]
(if-let [header (get-header-key response header)]
(apply update-in response [:headers header] f args)
response))
(defn- url? [^String s]
(try (URL. s) true
(catch MalformedURLException _ false)))
(defn- absolute-url [location request]
(if (url? location)
location
(let [url (URL. (req/request-url request))]
(str (URL. url location)))))
(defn absolute-redirects-response
"Convert a response that redirects to a relative URLs into a response that
redirects to an absolute URL. See: wrap-absolute-redirects."
[response request]
(if (redirect? response)
(update-header response "location" absolute-url request)
response))
(defn wrap-absolute-redirects
"Middleware that converts redirects to relative URLs into redirects to
absolute URLs. While many browsers can handle relative URLs in the Location
header, RFC 2616 states that the Location header must contain an absolute
URL."
[handler]
(fn
([request]
(absolute-redirects-response (handler request) request))
([request respond raise]
(handler request #(respond (absolute-redirects-response % request)) raise))))
ring-headers-0.3.0/src/ring/middleware/default_charset.clj 0000664 0000000 0000000 00000002266 13102426335 0023561 0 ustar 00root root 0000000 0000000 (ns ring.middleware.default-charset
"Middleware for automatically adding a charset to the content-type header in
response maps."
(:require [ring.util.response :as response]))
(defn- text-based-content-type? [content-type]
(or (re-find #"text/" content-type)
(re-find #"application/xml" content-type)))
(defn- contains-charset? [content-type]
(re-find #";\s*charset=[^;]*" content-type))
(defn default-charset-response
"Add a default charset to a response if the response has no charset and
requires one. See: wrap-default-charset."
[response charset]
(if response
(if-let [content-type (response/get-header response "Content-Type")]
(if (and (text-based-content-type? content-type)
(not (contains-charset? content-type)))
(response/charset response charset)
response)
response)))
(defn wrap-default-charset
"Middleware that adds a charset to the content-type header of the response if
one was not set by the handler."
[handler charset]
(fn
([request]
(default-charset-response (handler request) charset))
([request respond raise]
(handler request #(respond (default-charset-response % charset)) raise))))
ring-headers-0.3.0/src/ring/middleware/proxy_headers.clj 0000664 0000000 0000000 00000001547 13102426335 0023301 0 ustar 00root root 0000000 0000000 (ns ring.middleware.proxy-headers
"Middleware for handling headers set by HTTP proxies."
(:require [clojure.string :as str]))
(defn forwarded-remote-addr-request
"Change the :remote-addr key of the request map to the last value present in
the X-Forwarded-For header. See: wrap-forwarded-remote-addr."
[request]
(if-let [forwarded-for (get-in request [:headers "x-forwarded-for"])]
(let [remote-addr (str/trim (re-find #"[^,]*$" forwarded-for))]
(assoc request :remote-addr remote-addr))
request))
(defn wrap-forwarded-remote-addr
"Middleware that changes the :remote-addr of the request map to the
last value present in the X-Forwarded-For header."
[handler]
(fn
([request]
(handler (forwarded-remote-addr-request request)))
([request respond raise]
(handler (forwarded-remote-addr-request request) respond raise))))
ring-headers-0.3.0/src/ring/middleware/x_headers.clj 0000664 0000000 0000000 00000007436 13102426335 0022372 0 ustar 00root root 0000000 0000000 (ns ring.middleware.x-headers
"Middleware for adding various 'X-' response headers."
(:require [clojure.string :as str]
[ring.util.response :as resp]))
(defn- allow-from? [frame-options]
(and (map? frame-options)
(= (keys frame-options) [:allow-from])
(string? (:allow-from frame-options))))
(defn- format-frame-options [frame-options]
(if (map? frame-options)
(str "ALLOW-FROM " (:allow-from frame-options))
(str/upper-case (name frame-options))))
(defn- format-xss-protection [enable? options]
(str (if enable? "1" "0") (if options "; mode=block")))
(defn- wrap-x-header [handler header-name header-value]
(fn
([request]
(some-> (handler request) (resp/header header-name header-value)))
([request respond raise]
(handler request #(respond (some-> % (resp/header header-name header-value))) raise))))
(defn frame-options-response
"Add the X-Frame-Options header to the response. See: wrap-frame-options."
[response frame-options]
(some-> response (resp/header "X-Frame-Options" (format-frame-options frame-options))))
(defn wrap-frame-options
"Middleware that adds the X-Frame-Options header to the response. This governs
whether your site can be rendered in a ,