diff options
| author | eltrac <hi@eltr.ac> | 2026-04-29 15:57:04 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-04-29 15:57:04 +0800 |
| commit | 225c5c2d282cd77fd047e876b56e6c6b6e6bdb11 (patch) | |
| tree | 8f3b4c80b158ed42c440d4ba3bc0deeaf85a9f83 /src | |
| parent | 4acf82b39c1193469bf52e2a81b01133c14fb13f (diff) | |
fix: missing Content-Type in json response
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/retriever.clj | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/weepinbell/retriever.clj b/src/weepinbell/retriever.clj index 1d4f091..20ff686 100644 --- a/src/weepinbell/retriever.clj +++ b/src/weepinbell/retriever.clj @@ -5,12 +5,21 @@ ;; utilities (defn- respond-webmention-json [data] - (if data data + (if data + {:status 200 + :headers {"Content-Type" "application/json; charset=utf-8"} + :body data} ;; if no data found, respond 404 {:status 404 + :headers {"Content-Type" "application/json; charset=utf-8"} :body {:status 404 :message "Webmention does not exist or is pending for verification."}})) +(defn- respond-webmention-list-json [data] + {:status 200 + :headers {"Content-Type" "application/json; charset=utf-8"} + :body data}) + (defn- wrap-response-object [data] (let [result {:webmention (:webmention data)}] (cond-> result @@ -43,8 +52,9 @@ (by-domain domain nil)) ([domain typ] (cond->> (storage/get-wms-by-domain domain) - true wrap-response-list - typ (filter-response-by-mftype typ)))) + true wrap-response-list + typ (filter-response-by-mftype typ) + true respond-webmention-list-json))) (defn by-url "Get webmention sent to a particular URL." @@ -52,15 +62,17 @@ (by-url url nil)) ([url typ] (if url - (cond->> (get-domain url) - true storage/get-wms-by-domain - true (filter #(= url (get-in % [:webmention :target]))) - true wrap-response-list - typ (filter-response-by-mftype typ)) - ;; if no url query is passed - {:status 400 - :body {:status 400 - :message "Missing URL. Specify target URL whose webmentions you are querying."}}))) + (cond->> (get-domain url) + true storage/get-wms-by-domain + true (filter #(= url (get-in % [:webmention :target]))) + true wrap-response-list + typ (filter-response-by-mftype typ) + true respond-webmention-list-json) + ;; if no url query is passed + {:status 400 + :headers {"Content-Type" "application/json; charset=utf-8"} + :body {:status 400 + :message "Missing URL. Specify target URL whose webmentions you are querying."}}))) (defn by-id "Get one specific webmention by ID." |
