summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-09-11 15:12:22 +0800
committereltrac <hi@eltr.ac>2026-09-11 15:12:22 +0800
commit6bae4d80fc4a53d7c8a1d253f2d4ff6a6908f2f5 (patch)
tree58a4c400ea688022d1289bab91e7bb5b3c355a53 /src
parentc59595cda30fd7be01aa591aaaeacd243eabd7c4 (diff)
refactor(verifier, utils, webhook): replace hato with http-kit
since http-kit handle both server and client, hato as a client can be replaced
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/utils.clj8
-rw-r--r--src/weepinbell/verifier.clj16
-rw-r--r--src/weepinbell/webhook.clj4
3 files changed, 15 insertions, 13 deletions
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))))