This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-16
Channels
- # announcements (8)
- # aws (28)
- # babashka (26)
- # beginners (125)
- # calva (18)
- # chlorine-clover (2)
- # cider (12)
- # cljs-dev (6)
- # cljsrn (4)
- # clojure (134)
- # clojure-europe (31)
- # clojure-italy (2)
- # clojure-nl (14)
- # clojure-uk (83)
- # clojurescript (81)
- # conjure (4)
- # cursive (2)
- # datomic (145)
- # emacs (13)
- # events (3)
- # figwheel-main (14)
- # fulcro (30)
- # graalvm (23)
- # graphql (15)
- # helix (21)
- # jackdaw (20)
- # juxt (1)
- # lambdaisland (4)
- # leiningen (2)
- # malli (12)
- # meander (22)
- # observability (22)
- # off-topic (27)
- # pedestal (3)
- # re-frame (12)
- # reitit (1)
- # releases (2)
- # rewrite-clj (3)
- # shadow-cljs (67)
- # spacemacs (7)
- # sql (1)
- # tools-deps (19)
- # unrepl (2)
- # xtdb (25)
unfortunately HttpURLConnection does not allow PATCH
method, which the GitHub API requires 😞
If I remember correctly the github api supports the ?method=PATCH or {"method": "PATCH" ..other json stuff} when using POST
I resolved it with https://github.com/lvh/fix-default-branch/blob/trunk/src/io/lvh/fix_default_branch/https.clj
this is one of the reasons I built babashka.curl... Curl is amazingly useful in some niche cases. E.g. also when talking http over a unix socket
well, the issue is arguably that httpurlconnection has a hardcoded array of methods, if you use reflection to make that array a little less hardcoded...
I'll let you know how this works out:
(def ^:private modifiers-field
(doto (.getDeclaredField Field "modifiers")
(.setAccessible true)))
(defn allow-patch!
[]
(.setAccessible modifiers-field true)
(let [methods-field (doto (.getDeclaredField java.net.HttpURLConnection "methods")
(.setAccessible true))
not-final (bit-and-not (.getModifiers methods-field) Modifier/FINAL)]
(.setInt modifiers-field methods-field not-final)
(assert (not (-> methods-field .getModifiers Modifier/isFinal)))
;; Note, the order of operations here matters a lot! If you .get access
;; methods-field while it's still static final, the access result will be
;; cached, and this will fail even though ostensibly you disabled final.
(let [new-methods (-> (.get methods-field nil) seq (conj "PATCH"))]
(.set methods-field nil (into-array String new-methods)))))
(I regret to inform you there is no justice in the universe and the above worked just fine)
you have to do it at the right time though, if you change the order of operations even the patching itself fails in pure java
i definitely don't understand why the people who wrote that class decided to make HTTP methods static final
though
what about vendoring the HttpURLConnection class and fix this one thing? is it a big class?
@lvh clj-http says it supports patch, but might want to pay attention to the size increase of your binary
did a quick, small and probably naive POC with incorporating spec1 into babashka. it does work:
$ ./bb "(require '[clojure.spec.alpha :as s]) (s/def ::a int?) (s/explain-data ::a :foo)"
{:clojure.spec.alpha/problems [{:path [], :pred clojure.core/int?, :val :foo, :via [:user/a], :in []}], :clojure.spec.alpha/spec :user/a, :clojure.spec.alpha/value :foo}
but the binary grows with 35 megabytes (from 60 to 95) and the RAM usage grows also considerably. Might be worth digging into this some more, maybe the spec source can be vendored and curated a little bit, etc.