ring-clojure / ring-ssl Goto Github PK
View Code? Open in Web Editor NEWThis project forked from jcf/ring-ssl
Ring middleware for managing HTTPS requests
License: MIT License
This project forked from jcf/ring-ssl
Ring middleware for managing HTTPS requests
License: MIT License
Say I use wrap-ssl-redirect
for the case the user loads a website using http to get him redirected to the https version. I also use wrap-hsts
for the second time and so on, so that when the user tries to access the website using http, it is immediately converted to https before sending the request.
Then it happens that my new ssl certificate is unsecure and browsers start complaining. Many former users are still accessing the website via https, which will take them to a security page first. To make matters worse, even if they do use http, the link will immediately be converted to https due to the hsts cache.
To solve these issues, I came up with this:
(defn- build-hsts-expire-header
[{:keys [include-subdomains?] :or {include-subdomains? true}}]
(str "max-age=" 0
(if include-subdomains? "; includeSubDomains")))
(defn wrap-expire-hsts
{:arglists '([handler] [handler options])}
[handler & [{:as options}]]
(fn [request]
(-> (handler request)
(resp/header "Strict-Transport-Security" (build-hsts-expire-header options)))))
(defn- http-url [url-string port]
(let [url (java.net.URL. url-string)]
(str (java.net.URL. "http" (.getHost url) (or port 80) (.getFile url)))))
(defn- get-request? [{method :request-method}]
(or (= method :head)
(= method :get)))
(defn wrap-insecure-redirect
"Middleware that redirects any HTTPS request to the equivalent HTTP URL.
Accepts the following options:
:port - the port to use for redirects, defaults to 80."
{:arglists '([handler] [handler options])}
[handler & [{:keys [port]}]]
(fn [request]
(if (= (:scheme request) :https)
(-> (resp/redirect (http-url (req/request-url request) port))
(resp/status (if (get-request? request) 301 307)))
(handler request))))
Is there an easier way to solve this? If not, how about including this use case in ring-ssl
along the lines of undoing ssl?
Is there a tutorial somewhere. so I can set up a stand alone ring server with self signed TLS cert?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.