Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Commit

Permalink
Block bots
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopch committed Jun 23, 2012
1 parent 61f03ee commit 92a4bc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/isbnnetinclj/middleware/block.clj
@@ -0,0 +1,22 @@
(ns isbnnetinclj.middleware.block
(:require [timbre.core :as log]
[noir.core :refer :all]))


(def bots
'(#"kitabcompare"))


(defn should-block?
[user-agent]
(some #(re-find % user-agent) bots))


;; http://webnoir.org/tutorials/middleware
(defn block-bots
[handler]
(fn [request]
(let [user-agent (get-in request [:headers "user-agent"])]
(if (should-block? user-agent)
nil
(handler request)))))
4 changes: 3 additions & 1 deletion src/isbnnetinclj/server.clj
Expand Up @@ -2,9 +2,11 @@
(:gen-class) (:gen-class)
(:require [timbre.core :as log] (:require [timbre.core :as log]
[noir.server] [noir.server]
[isbnnetinclj.models.mongodb :as mongodb])) [isbnnetinclj.models.mongodb :as mongodb]
[isbnnetinclj.middleware.block :refer [block-bots]]))




(noir.server/add-middleware block-bots)
(noir.server/load-views "src/isbnnetinclj/views/") (noir.server/load-views "src/isbnnetinclj/views/")




Expand Down

0 comments on commit 92a4bc0

Please sign in to comment.