This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-17
Channels
- # announcements (2)
- # asami (3)
- # babashka (30)
- # beginners (23)
- # calva (28)
- # cider (3)
- # clj-kondo (16)
- # clj-on-windows (7)
- # cljs-dev (7)
- # clojure (47)
- # clojure-austin (3)
- # clojure-europe (25)
- # clojure-gamedev (3)
- # clojure-greece (1)
- # clojure-nl (1)
- # clojure-uk (3)
- # clojurescript (54)
- # community-development (24)
- # conjure (16)
- # duct (1)
- # emacs (8)
- # events (1)
- # figwheel-main (4)
- # fulcro (13)
- # gratitude (20)
- # helix (3)
- # honeysql (8)
- # hyperfiddle (12)
- # introduce-yourself (1)
- # jobs (6)
- # lambdaisland (1)
- # lsp (35)
- # malli (1)
- # meander (27)
- # minecraft (11)
- # off-topic (12)
- # pathom (1)
- # portal (11)
- # releases (1)
- # remote-jobs (1)
- # ring (11)
- # sci (1)
- # shadow-cljs (53)
- # specter (5)
- # xtdb (20)
Is there an easy way to read a map that has been printed in a way that the strings have not been quoted. clojure.edn/read quite rightly complains…
(clojure.edn/read "{:id :sqa.resources/allocations-categories, :request-id #uuid faebb10a-3350-49e5-ad54-62e2ebec3a37, :user-id 6727, :uri /allocation_categories, :method :get, :status 200, :time 230, :query-string device_sqid=P14637}")
In general, you can't even write such a reader yourself - because :query-string
can include ,
without percent-encoding it.
You might be able to get away with writing a custom parser if you can make a lot of assumptions.
ahh hot damn
btw, if you can adjust how this line is printed - there are a prn
and pr-str
that emits a string suitable for edn reader.
yep, think that’s what I’m gonna do going forward - just have a lot of existing logs printed that way 😄
thanks!!
Is there any way to determine if direct-linking was enabled when the JAR was compiled?
I just turned it on by adding jvm-opts to lein uberjar profile, but I'd like to confirm that it is really working before deploying.
Ha okay, this seemed to work 🙂 I added (println "Compiler options" clojure.core/*compiler-options*)
and it printed map with direct-linking true so seems to be working
if you want to be sure you can always check the behaviour with and without the setting
(defn a [] 1)
(defn -main
[& args]
(def a (fn [] 2))
(println (a)))
Hello, I'm trying to do some http endpoint redirection to preserve backwards compatibility. As part of this, I require some modification of the request body.
I tried doing this with ring middleware as shown but I am getting {:error \"Malformed \\\"application/edn\\\" request.\"}"
I'm not sure if it is affected by the content length but doesn 't seem to work either way.
The body changes from :body = HttpInputOverHTTP@456325a[c=81,q=0,[0]=null,s=EOF] to :body = http://java.io.StringReader@4dee01
(defn crux->xtdb-request [request]
(update-in request [:body]
(fn [x] (-> (slurp x)
(str/replace #"crux.tx/" "xtdb.api/")
(str/replace #"crux.db/" "xt/")
(java.io.StringReader.)))))
(defn- route-crux-requests-2 [handler]
(fn [request]
(let [{:keys [uri]} request]
(if (= uri "/_crux/submit-tx")
(do
(def request request)
(def request-2 (crux->xtdb-request request))
(handler (-> (crux->xtdb-request request)
(assoc :uri "/_xtdb/submit-tx")
;; (update :content-length - 5)
)))
(handler request)))))
Can anyone advise? :oyou don't need to make StringReader from the body content. and a small note to the way you debug middleware: before applying middleware in the request :body you have HttpInputOverHTTP. it is a mutable object and when you call slurp you drain its content. Thats why you see EOF
When I leave it as a string i instead get Bad request
"{:spec \"(juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.core/spec {:spec (clojure.spec.alpha/keys :opt [:xtdb.api/submit-tx-opts] :req-un [:xtdb.http-server/tx-ops]), :type :map, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/key->spec {:xtdb.api/submit-tx-opts :xtdb.api/submit-tx-opts, :tx-ops :xtdb.http-server/tx-ops}, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys #{:xtdb.api/submit-tx-opts :tx-ops}, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys-req #{:tx-ops}, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys-opt #{:xtdb.api/submit-tx-opts}, :leaf? false})\", :problems [{:path [], :pred \"clojure.core/map?\", :val nil, :via [:xtdb.http-server/submit-tx-spec], :in []}], :type :juxt.clojars-mirrors.reitit-core.v0v5v15.reitit.coercion/request-coercion, :coercion :spec, :value nil, :in [:request :body-params]}",
looks like empty request. but I can't say for sure without knowing what middlewares you have and how you handle the request.
you can try adding https://cljdoc.org/d/metosin/reitit/0.5.18/doc/ring/default-middleware#inspecting-middleware-chain to debug how your request transform during handling
Can't seem to get that middleware to work - very clear how it works from the examples in the repos :x
My middleware within reitit is basically the ones similar to here and am uncommenting the print-request-diffs that is commented out here https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj
Okay I'm fairly confused but seems like this works now
(defn route-crux-requests-3 [handler]
(fn [request]
(let [{:keys [uri]} request]
(if (= uri "/_crux/submit-tx")
(let [body-str (ring.util.request/body-string request)
stuff (-> request
(assoc :uri "/_xtdb/submit-tx")
(assoc :body (-> body-str
(str/replace #"crux.tx/" "xtdb.api/")
(str/replace #"crux.db/" "xt/"))))]
(handler stuff))
Guess maybe it was the slurpNow this is some weirdness: Why is invoke()
manually specified 20 times by the number of arguments? https://clojure.github.io/clojure/javadoc/clojure/lang/IFn.html
Someone actually asked this few days ago: https://clojurians.slack.com/archives/C03S1KBA2/p1652454186898339
something to keep in mind if you are used to writing java is that at the jvm level java varargs are arrays, so if .invoke was just specified as a single java method taking varargs, at the jvm level it would be a method taking an Object array
you don't have direct access to the stack, so java implements varargs by inserting array creation, which makes java varargs too expensive for general function application
I know for sure rich wrote some code to generate all the overloads for primitive arguments, so it seems likely most of the invoke methods got that as well
Does the Luminus have something similar to the Security Filter Chain that the Java Spring framework provides?
In the case of jetty at least, the (a?) ring adapter has a key called :configurator where you can do arbitrary things before server start
Pretty much anything. ring.adapter.jetty/run-jetty
will create a Jetty Server
instance initialized with the options passed in the options
map parameter, then pass the Server
instance to the :configurator
function
have a look at https://github.com/matasaru/tiger-webapp/blob/dev/src/main/clj/tiger/main.clj
Or can I just import the Spring Security libs into Luminus?