diff options
| author | eltrac <hi@eltr.ac> | 2026-03-17 10:33:58 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-03-17 10:33:58 +0800 |
| commit | ce13717aa287c1e2347b168e3fdcf8a3084ca472 (patch) | |
| tree | 6c90636240ae9e669e2ebb394d7a2c047bbafafe | |
| parent | fb8ac7de828ff9804011e1d80240862fbcc28c1b (diff) | |
feat: receiver now respond with 201, JSON body and Location Header
| -rw-r--r-- | src/weepinbell/receiver.clj | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj index 889bc86..d24092a 100644 --- a/src/weepinbell/receiver.clj +++ b/src/weepinbell/receiver.clj @@ -2,7 +2,10 @@ "Receiver receives Webmention request (a source and a target); verify the request; return error message if any; push Webmention into queue of processor." (:require [clojure.string :as string] [clojure.core.async :refer [put!]] - [weepinbell.utils :refer [validate-urls validate-target]])) + [weepinbell.utils :refer [validate-urls validate-target]] + [weepinbell.config :refer [get-config]] + [digest :as digest] + [cheshire.core :as json])) (defn verify-request [source target] @@ -38,9 +41,15 @@ ;; Webmention verification SHOULD be handled asynchronously ;; to prevent DoS (Denial of Service) attacks. (put! wmc wm) - ;; respond with 202 when Webmention passed checks and - ;; was sent into queue. - {:status 202 - :headers {"Content-Type" "text/plain"} - :body "Webmention accepted"})))) + ;; respond with 201 when Webmention passed checks and + ;; was sent into queue, include a Location header + (let [wm-id (digest/md5 (str source target)) + wm-url (str (get-config :base-url) "/api/mention/" wm-id) + response {:status 201 + :message "Webmention is accepted and pending for verification." + :url wm-url}] + {:status 201 + :headers {"Location" wm-url} + :body (json/generate-string response)}))))) + |
