diff options
| author | eltrac <hi@eltr.ac> | 2026-03-03 09:39:13 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-03-03 09:39:13 +0800 |
| commit | f07f6db9cec2a27c4abcbe8b012fd13e6f89f115 (patch) | |
| tree | a47fac29276c9d31f5293e33b8070c716db1019d | |
| parent | adcd1767b5a2c7a3452780cd328e1d8a46c06fb2 (diff) | |
style: add comment and docstrings
| -rw-r--r-- | src/weepinbell/receiver.clj | 11 |
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 |
