summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@eltr.ac>2026-09-11 09:14:36 +0200
committerEltrac <hi@eltr.ac>2026-09-11 09:14:36 +0200
commite6db9f8be7959f3f424f9c39d4e461d3fd0b3d39 (patch)
tree58a4c400ea688022d1289bab91e7bb5b3c355a53
parent7064f647d2829a4833227854857caf8a7e05776c (diff)
parent12e2f3bb360bf3f0d8cf34b43c8586dfb8412119 (diff)
Merge pull request 'Replace hato and ring-jetty-adapter with http-kit #9' (#14) from refact_httpkit into master
Reviewed-on: https://codeberg.org/eltrac/weepinbell/pulls/14
-rw-r--r--project.clj3
-rw-r--r--src/weepinbell/core.clj6
-rw-r--r--src/weepinbell/utils.clj8
-rw-r--r--src/weepinbell/verifier.clj16
-rw-r--r--src/weepinbell/webhook.clj4
-rw-r--r--test/weepinbell/test_utility.clj6
-rw-r--r--test/weepinbell/webhook_test.clj6
7 files changed, 24 insertions, 25 deletions
diff --git a/project.clj b/project.clj
index 1271cd2..4d8d5a3 100644
--- a/project.clj
+++ b/project.clj
@@ -7,11 +7,10 @@
[compojure "1.7.2"]
[ring/ring-core "1.15.4"]
[ring/ring-defaults "0.7.0"]
+ [http-kit "2.3.0"]
[ring/ring-json "0.5.1"]
- [ring/ring-jetty-adapter "1.15.3"]
[cheshire "6.1.0"]
[commons-validator "1.10.1"]
- [hato "1.0.0"]
[com.kylewm/mf2j "0.0.4"]
[com.taoensso/timbre "6.8.0"]
[hiccup "2.0.0"]
diff --git a/src/weepinbell/core.clj b/src/weepinbell/core.clj
index 0af2288..709473e 100644
--- a/src/weepinbell/core.clj
+++ b/src/weepinbell/core.clj
@@ -1,5 +1,5 @@
(ns weepinbell.core
- (:require [ring.adapter.jetty :refer [run-jetty]]
+ (:require [org.httpkit.server :refer [run-server]]
[clojure.spec.alpha :as s]
[weepinbell.processor :as processor]
[weepinbell.handler :refer [app]]
@@ -32,7 +32,5 @@
;; Start receiver server
;; Check for a PORT environment variable, default to 3000
(let [port (Integer/parseInt (or (:port config) (System/getenv "PORT") "3000"))]
- (run-jetty
- (app wmc store config)
- {:port port :join? true})))
+ (run-server (app wmc store config) {:port port :join? true})))
diff --git a/src/weepinbell/utils.clj b/src/weepinbell/utils.clj
index 20ade7d..78068ef 100644
--- a/src/weepinbell/utils.clj
+++ b/src/weepinbell/utils.clj
@@ -1,7 +1,7 @@
(ns weepinbell.utils
(:import [org.apache.commons.validator.routines UrlValidator]
[java.net URI])
- (:require [hato.client :as hc]
+ (:require [org.httpkit.client :as hk]
[clojure.string :as string]
[clojure.walk :as walk]
[clojure.java.io :as io]
@@ -34,14 +34,14 @@
parent-dir (.getParentFile file)]
(when (and parent-dir (not (.exists parent-dir)))
(.mkdirs parent-dir))
- (let [response (hc/get url {:as :stream
+ (let [response (hk/get url {:as :stream
:timeout 30000})
- content-length (get-in response [:headers "content-length"])]
+ content-length (get-in @response [:headers "content-length"])]
(timbre/info "Downloading [" url "] -> [" dest-path "]")
(when content-length
(timbre/info "File size:" content-length "bytes"))
;; write to output stream
- (with-open [in (:body response)
+ (with-open [in (:body @response)
out (io/output-stream file)]
(io/copy in out))
(timbre/info "Download success.")
diff --git a/src/weepinbell/verifier.clj b/src/weepinbell/verifier.clj
index f8c9fe1..95ea686 100644
--- a/src/weepinbell/verifier.clj
+++ b/src/weepinbell/verifier.clj
@@ -5,11 +5,13 @@
2) source respond with 2** status code.
3) source's Content-Type is either HTML or plain text."
(:require [clojure.string :refer [includes?]]
- [hato.client :as hc]
+ [org.httpkit.client :as hk]
[taoensso.timbre :as timbre]))
-(defn- verify-content-type [content-type]
- (#{:text/html :text/plain} content-type))
+(defn- verify-headers [headers]
+ (#{"text/html" "text/plain"} (:content-type headers)))
+
+(verify-headers {:content-type "text/html"})
(defn verify-mention
"Get source and follow redirects to check if target link is present."
@@ -17,13 +19,13 @@
(try
(timbre/info (str "Verifying mention from: " source))
;; get first 1MB of source URL and verify
- (let [{:keys [status body content-type]} (hc/get source {:headers {"Range" "bytes=0-1048575"}})
- target-content-type (:content-type (hc/head target))]
+ (let [{:keys [status body headers]} @(hk/get source {:headers {"Range" "bytes=0-1048575"}})
+ target-headers (:headers @(hk/head target))]
;; Verify status code
(if (and (>= status 200) (< status 300))
;; Verify Content-Types
- (if (and (verify-content-type content-type)
- (verify-content-type target-content-type))
+ (if (and (verify-headers headers)
+ (verify-headers target-headers))
;; Verify inclusion of target URL
;; TODO needs to be more robust
(if (includes? (str body) target)
diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj
index c5a2bae..0090243 100644
--- a/src/weepinbell/webhook.clj
+++ b/src/weepinbell/webhook.clj
@@ -1,5 +1,5 @@
(ns weepinbell.webhook
- (:require [hato.client :as hc]
+ (:require [org.httpkit.client :as hk]
[taoensso.timbre :as timbre]
[weepinbell.utils :refer [valid-http-url?]]))
@@ -15,7 +15,7 @@
(filter string?)
(filter valid-http-url?)))]
(->> hooks
- (map #((hc/post %)
+ (map #(@(hk/post %)
(timbre/info "Webhook triggered: " %)))
doall))))
diff --git a/test/weepinbell/test_utility.clj b/test/weepinbell/test_utility.clj
index 0dfbfc4..22a6549 100644
--- a/test/weepinbell/test_utility.clj
+++ b/test/weepinbell/test_utility.clj
@@ -1,6 +1,6 @@
(ns weepinbell.test-utility
(:require [compojure.core :refer [GET routes]]
- [ring.adapter.jetty :refer [run-jetty]]
+ [org.httpkit.server :refer [run-server]]
[weepinbell.processor :as p]))
(def mock-callbacks {:on-create (fn [])
@@ -21,11 +21,11 @@
:update (fn [~'_ ~'_ ~'_] (deliver ~'updated true))
:delete (fn [~'_ ~'_] (deliver ~'deleted true))
:get (fn [~'_ ~'_] (= ~existance :old))}
- ~'server (run-jetty handler# {:port 38888 :join? false})]
+ ~'server (run-server handler# {:port 38888 :join? false})]
(p/process-webmention {:s ~source-url :t ~target-url}
mock-callbacks
~'storage
{})
~@body
- (.stop ~'server))))
+ (~'server))))
diff --git a/test/weepinbell/webhook_test.clj b/test/weepinbell/webhook_test.clj
index a0307cc..c0fd984 100644
--- a/test/weepinbell/webhook_test.clj
+++ b/test/weepinbell/webhook_test.clj
@@ -1,6 +1,6 @@
(ns weepinbell.webhook-test
(:require [clojure.test :refer [testing is deftest]]
- [ring.adapter.jetty :refer [run-jetty]]
+ [org.httpkit.server :refer [run-server]]
[weepinbell.webhook :as webhook]))
(deftest webhook-test
@@ -9,9 +9,9 @@
handler (fn [_]
(deliver received true)
{:status 200 :headers {} :body "ok"})
- server (run-jetty handler {:port 18888 :join? false})]
+ server (run-server handler {:port 18888 :join? false})]
(webhook/trigger :on-create
{:on-create ["http://127.0.0.1:18888/webhook-test"]})
(is (deref received 2000 nil)
"Webhook request was received")
- (.stop server))))
+ (server))))