pax_global_header00006660000000000000000000000064131024263350014511gustar00rootroot0000000000000052 comment=3c803eb0864d7fbe93ba1595d5d0d6ae09d51eb0 ring-headers-0.3.0/000077500000000000000000000000001310242633500140615ustar00rootroot00000000000000ring-headers-0.3.0/.gitignore000066400000000000000000000001331310242633500160460ustar00rootroot00000000000000/target /classes /checkouts /codox pom.xml pom.xml.asc *.jar *.class /.lein-* /.nrepl-port ring-headers-0.3.0/.travis.yml000066400000000000000000000000501310242633500161650ustar00rootroot00000000000000language: clojure script: lein test-all ring-headers-0.3.0/README.md000066400000000000000000000007611310242633500153440ustar00rootroot00000000000000# Ring-Headers [![Build Status](https://travis-ci.org/ring-clojure/ring-headers.svg?branch=master)](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.clj000066400000000000000000000014621310242633500162240ustar00rootroot00000000000000(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/000077500000000000000000000000001310242633500146505ustar00rootroot00000000000000ring-headers-0.3.0/src/ring/000077500000000000000000000000001310242633500156075ustar00rootroot00000000000000ring-headers-0.3.0/src/ring/middleware/000077500000000000000000000000001310242633500177245ustar00rootroot00000000000000ring-headers-0.3.0/src/ring/middleware/absolute_redirects.clj000066400000000000000000000033011310242633500242750ustar00rootroot00000000000000(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.clj000066400000000000000000000022661310242633500235610ustar00rootroot00000000000000(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.clj000066400000000000000000000015471310242633500233010ustar00rootroot00000000000000(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.clj000066400000000000000000000074361310242633500223720ustar00rootroot00000000000000(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 ,