001 (ns clj-activitypub.internal.http-util
002 "copied from [Jahfer's clj-activitypub library](https://github.com/jahfer/clj-activitypub).
003 If and when Jahfer issues a release of that library, this directory will be deleted and a
004 dependency on that library will be added to the project."
005 (:require [clj-activitypub.internal.crypto :as crypto])
006 (:import (java.net URLEncoder)
007 (java.time OffsetDateTime ZoneOffset)
008 (java.time.format DateTimeFormatter)))
009
010 (defn encode-url-params [params]
011 (->> params
012 (reduce-kv
013 (fn [coll k v]
014 (conj coll
015 (str (URLEncoder/encode (name k)) "=" (URLEncoder/encode (str v)))))
016 [])
017 (interpose "&")
018 (apply str)))
019
020 (defn date []
021 (-> (OffsetDateTime/now (ZoneOffset/UTC))
022 (.format DateTimeFormatter/RFC_1123_DATE_TIME)))
023
024 (defn digest
025 "Accepts body from HTTP request and generates string
026 for use in HTTP `Digest` request header."
027 [body]
028 (str "sha-256=" (crypto/sha256-base64 body)))