summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/receiver.clj11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj
index 351944c..4a9c4b0 100644
--- a/src/weepinbell/receiver.clj
+++ b/src/weepinbell/receiver.clj
@@ -5,10 +5,12 @@
(:require [weepinbell.config :refer [get-config]]
[clojure.core.async :refer [go chan >!]]))
+;; validation utilities
(defn valid-http-url? [url]
(let [schemes (into-array String ["http" "https"])
validator (UrlValidator. schemes)]
(.isValid validator url)))
+
(defn validate-urls [s t]
(and (valid-http-url? s) (valid-http-url? t)))
@@ -16,8 +18,11 @@
(let [allow-list (get-config :allowed-target-domains)
target-domain (-> (URI/create t) .getHost)]
(some #{target-domain} allow-list)))
+;; validation utilities end
-(defn verify-request [s t]
+(defn verify-request
+ "Receive source and target of webmention; performs a series of checks; return a list of error responses or nil values. nil means the check has passed. The caller needs to return the first errror response if any."
+ [s t]
(let [checks [;; The receiver MUST check that source and target are valid URLs [URL]
;; and are of schemes that are supported by the receiver.
[(validate-urls s t) "Invalid URLs. Source and target have to be http(s) urls."]
@@ -33,7 +38,9 @@
(def wmc (chan)) ;; webmention queue
-(defn receive [wm]
+(defn receive
+ "Receive webmention; call verify-request; if verification passed, push webmention into queue."
+ [wm]
(let [{:keys [s t]} wm
verification (verify-request s t)]
;; Request verification