invetica/redirects

Canonical redirects for your URL.


Keywords
clojure, http, redirects, ring
License
MIT

Documentation

Redirects converts requests into redirects ensuring your traffic lands on your canonical URL.

Contents

Usage

(ns app.service
  (:require [invetica.redirects :as redirects]))

;; Create a registry of hostnames you want to redirect to a canonical
;; (optionally with HTTPS scheme) URL.
(def registry
  (redirects/compile-sites
   #{{:site/canonical "www.example.com"}
     {:site/canonical "www.invetica.co.uk"
      :site/aliases #{"invetica.co.uk"
                      "invetika.co.uk"}
      :site/https? true}}))

;; Call `invetica.redirects/canonical-redirect` with your compiled registry, and
;; the request map.
;;
;; If a redirect is needed, a Ring-compatible response map will be returned. If
;; not, you'll get `nil` back.
(redirects/canonical-redirect
 registry
 {:headers {"host" "example.com"}
  :query-string "a=b&c=d"
  :request-method :get
  :scheme :http
  :server-name "example.com"
  :uri "/foo"})

;; => {:status 302,
;;     :headers {"Location" "http://example.com/foo?a=b&c=d"}
;;     :body ""}

License

The MIT License (MIT)

Copyright © 2017 Invetica Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.